前言:
现时小伙伴们对“php获取当前经纬度”大致比较重视,姐妹们都需要学习一些“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获取当前经纬度