1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > php根据位置获取经纬度(百度地图)

php根据位置获取经纬度(百度地图)

时间:2023-06-11 07:03:08

相关推荐

php根据位置获取经纬度(百度地图)

注意:申请的ak填写服务器端

1.根据地址获取经纬度

/**根据位置获取经纬度* @param $area* @return mixed*/protected function getLonLLat($area){if (!$area){echo "地址不能为空";}$ak = "自己申请的ak";$url = "http://api./geocoding/v3/?";$params = array('address'=>$area,'output'=>"json",'ak'=>$ak);$url = $url.http_build_query($params);$result = $this->curl_http($url,$params);return json_decode($result,true);}

2.根据经纬度获取地址

/*** [@getAddressByLatlng 根据经纬度获取地址]* @param $lat* @param $lng* @return string*/public function getAddressByLatlng($lat,$lng){$ak = "xYIqhNqUWDYXuUwZqgG079j1GcfxYa82";$address = '';if($lat && $lng){$apiurl = 'http://api./geoconv/v1/?coords='.$lng.','.$lat.'&from=1&to=5&ak='.$ak;$file = file_get_contents($apiurl);$arrpoint = json_decode($file, true);$arr = $arrpoint['result'][0];$url = 'http://api./reverse_geocoding/v3/?ak='.$ak.'&output=json&coordtype=wgs84ll&location='.$arr['y'].','.$arr['x'];$content = file_get_contents($url);$place = json_decode($content,true);$address = $place['result']['formatted_address'];}return $address;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。