<?php
//固定好的key值,用的是高德地图的api接口
$key="3434344sdss3444334333";
//根据经纬度获取详细地址
//https://restapi.amap.com/v3/geocode/regeo?output=json&location=116.310003,39.991957&key=b2f20184545gdfgd1bc962c480cd&radius=1000&extensions=all
$latitude="136.659962";//纬度36.659962
$longitude="113.799176";//经度113.799176
$local="$longitude,$latitude";
$regeo_url="https://restapi.amap.com/v3/geocode/regeo";
$address_location=$regeo_url."?output=JSON&location=$local&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'];
$address=array();
if($local_status==1 && $local_infocode== 10000 ){
//地址信息的数组
$local_regeocode=$result_local['regeocode'];
//详细地址信息的数组
$addressComponent=$local_regeocode['addressComponent'];
$address['country']=$addressComponent['country'];//国家
$address['province']=$addressComponent['province'];//省份
$address['city']=$addressComponent['city'];//城市
$address['district']=$addressComponent['district'];//区县
}else{
echo "不能查询出数据";
}
echo "<pre>";
print_r($address);
?>
网友评论