记录:利用高德地图API,根据用户地址获取经纬度
API文档:
https://lbs.amap.com/api/webservice/guide/api/georegeo
调用API代码
<?php
/*** 服务器接口类*/
namespace queryAreaInfo;class queryArea{// 根据详细地址获取经纬度public function getLatLngByAddress($address){//高德地图的api接口,根据详细地址获取经纬度$regeo_url="https://restapi.amap.com/v3/geocode/geo";$key="web服务类型Key";$address_location=$regeo_url."?output=JSON&address=$address&key=$key";$data_location=file_get_contents($address_location);$result_local=json_decode($data_location,true);//返回数据状态1 为成功 0 为失败$local_status=$result_local['status'];//返回状态码 10000 为正确 其他为错误$local_infocode=$result_local['infocode'];// return $result_local;if($local_status==1 && $local_infocode== 10000 ){//地址信息的数组$local_geocode=$result_local['geocodes'];$location=$local_geocode[0]['location'];$location_ay=explode(",",$location);return ['status'=>1,'data'=>['longitude'=>$location_ay[0],'latitude'=>$location_ay[1],]];}else{return ['status'=>0, 'msg'=>'地图API调用失败'];}}}
use queryAreaInfo\queryArea;
public function getAboutAfterSale(){ //高德地图的api接口,根据详细地址获取 经纬度$address="河南";$queryArea=new queryArea();$result=$queryArea->getLatLngByAddress($address);echo '<pre>';print_r($result);}