您的位置 首页 php

php根据前端传递的经纬度获取区域地址信息

public function getCity()
 {
 $param = $this->request->param();
 if (empty($param['lat']) && empty($param['lon'])) {
 return $this->exitJson('1', '定位失败,请打开定位权限');
 }
 //维度
 $lat = $param['lat'];
 //经度
 $lon = $param['lon'];
 $key = "去百度开放平台获取(免费的)"; 
 if($lat>0 && $lon>0){
 $lbsUrl = "{$key}&coordtype=wgs84ll&location=".$lat.",".$lon."&output=json&pois=1";
 $curlRes = file_get_contents($lbsUrl);
 $res = json_decode($curlRes, TRUE);
 //var_dump($res);
 if ($res['status'] == 0 && !empty($res['result']['addressComponent']['city'])) {
 $data['province'] = $res['result']['addressComponent']['province'];
 $data['city'] = $res['result']['addressComponent']['city'];
 $data['district'] = $res['result']['addressComponent']['district'];
 }else{
 $data['province'] = '河南省';
 $data['city'] = '郑州市';
 $data['district'] = ' 二七区 ';
 }
 }else{
 $data['province'] = '河南省';
 $data['city'] = '郑州市';
 $data['district'] = '二七区';
 }

 return $this->exitJson('0', '返回地址', $data);
 } 

文章来源:智云一二三科技

文章标题:php根据前端传递的经纬度获取区域地址信息

文章地址:https://www.zhihuclub.com/150230.shtml

关于作者: 智云科技

热门文章

网站地图