/** * 根据地址获取经纬度 */ public static function getLoaction($local) { $address = urlencode($local[0].$local[1]); $url = "https://apis.map.qq.com/jsapi?qt=geoc&addr={$address}&key=TU5BZ-MKD3W-L43RW-O3ZBW-GWMZK-QBB25&output=jsonp&pf=jsapi&ref=jsapi"; $res = file_get_contents($url); $content = iconv("GBK", "UTF-8//IGNORE", $res); $array = @json_decode($content,true); $data['lat'] = $array['detail']['pointy']; $data['lon'] = $array['detail']['pointx']; return $data; } /** * 根据经纬度获取地址 * @param $ip * @param string $memberInfo * @return array */ private static function GetIpLookup($ip) { $url = 'https://apis.map.qq.com/jsapi?qt=rgeoc&lnglat='.urlencode($ip).'&key=TU5BZ-MKD3W-L43RW-O3ZBW-GWMZK-QBB25&output=jsonp&pf=jsapi&ref=jsapi'; $res = file_get_contents($url); $content = iconv("GBK", "UTF-8//IGNORE", $res); $array = @json_decode($content,true); if (!is_array($array)) { return []; } $addr_info = []; foreach ($array['detail']['poilist'] as $k => $v) { if (!empty($v['addr_info']['c']) && !empty($v['pointx'])) { $addr_info[$k]['pointx'] = $v['pointx']; $addr_info[$k]['pointy'] = $v['pointy']; } } if (empty($addr_info)) { foreach ($array['detail']['results'] as $k => $v) { $addr_info[$k]['pointx'] = $v['pointx']; $addr_info[$k]['pointy'] = $v['pointy']; break; } } return $addr_info; }