首页 > 编程语言 >高德地图地址转化为经纬度(php)

高德地图地址转化为经纬度(php)

时间:2022-12-16 10:01:15浏览次数:70  
标签:https 经纬度 地址 location key php 高德 amap

高德地图地址转化为经纬度(php)

高德地图开放平台:https://developer.amap.com/

1、注册一个高德开放平台

链接地址:https://lbs.amap.com/dev/id/choose

2、创建一个应用,并添加一个key

image-20210215095435122

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];

 

标签:https,经纬度,地址,location,key,php,高德,amap
From: https://www.cnblogs.com/gaoyusui/p/16986580.html

相关文章