/**
* [getRealyAddress 获取具体位置]
* @author sunlq 2018-02-28
* @param [type] $lat [纬度]
* @param [type] $lng [经度]
* @return [type] [description]
*/
public function getRealyAddress($lat,$lng)
{
$address = '';
if($lat && $lng)
{
$arr = $this->changeToBaidu($lat,$lng);
$url = 'http://api.map.baidu.com/geocoder/v2/?callback=&location='.$arr['y'].','.$arr['x'].'.&output=json&pois=1&ak=fKvpmBXsoCcx8AMGqOThmd2ZEXHpniVq';
$content = file_get_contents($url);
$place = json_decode($content,true);
$address = $place['result']['formatted_address'];
}
return $address;
}
/**
* [changeToBaidu 转换为百度经纬度]
* @author sunlq 2018-05-28
* @param [type] $lat [description]
* @param [type] $lng [description]
* @return [type] [description]
*/
public function changeToBaidu($lat,$lng)
{
$apiurl = 'http://api.map.baidu.com/geoconv/v1/?coords='.$lng.','.$lat.'&from=1&to=5&ak=fKvpmBXsoCcx8AMGqOThmd2ZEXHpniVq';
$file = file_get_contents($apiurl);
$arrpoint = json_decode($file, true);
return $arrpoint['result'][0];
}
php根据经纬度获取地理位置
最新推荐文章于 2022-01-11 15:10:08 发布