城市名获取经纬度

public function GetADI($name = '')
    {
        $url = "http://api.map.baidu.com/geocoder?address=" . $name . "&output=json&key=37492c0ee6f924cb5e934fa08c6b1676";
        $ch  = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        $file_data = curl_exec($ch);
        curl_close($ch);
        $file_data = json_decode($file_data, true);
        if ($file_data['status'] == 'OK') {
            $add[] = $file_data['result']['location']['lng'];
            $add[] = $file_data['result']['location']['lat'];
            return $add;
        }
    }

猜你喜欢

转载自blog.csdn.net/hd2killers/article/details/80939261