高德地圖地址轉化為經緯度(php)
高德地圖開放平台:https://developer.amap.com/
1、注冊一個高德開放平台
2、創建一個應用,並添加一個key
3、根據web服務中的地理逆地理編碼API文檔實現
鏈接地址:https://developer.amap.com/api/webservice/guide/api/georegeo
示例代碼:
//接收地址信息
$address = $_POST['addresss'];
//創建應用生成的key
$key = config('gaode.key');
//根據開發文檔獲取經緯度
$url = "https://restapi.amap.com/v3/geocode/geo?key=" . $key . "&address=" . $address;
$json = file_get_contents($url);
$GaoDeArr = json_decode($json,true);
if ($GaoDeArr['infocode'] != '10000'){
return $this->msg(1,'地址信息輸入錯誤');
}
$location = explode(',' , $GaoDeArr['geocodes'][0]['location']);
//經度
$longitude = $location[0];
//緯度
$latitude = $location[1];