/**
 * @param string $address 地址
 * @param string $city  城市名
 * @return array
 */
function getLatLng($address='',$city='')
{
    $result = array();
    $ak = '';//您的百度地图ak,可以去百度开发者中心去免费申请
    $url ="http://api.map.baidu.com/geocoder/v2/?callback=renderOption&output=json&address=".$address."&city=".$city."&ak=".$ak;
    $data = file_get_contents($url);
    $data = str_replace('renderOption&&renderOption(', '', $data);
    $data = str_replace(')', '', $data);
    $data = json_decode($data,true);
    if (!empty($data) && $data['status'] == 0) {
        $result['lat'] = $data['result']['location']['lat'];
        $result['lng'] = $data['result']['location']['lng'];
        return $result;//返回经纬度结果
    }else{
        return null;
    }
 
}

来自微信公众号:编程社

PHP通过地址获取经纬度【百度地图API】

程序员日常进阶宝典,欢迎关注!

相关文章:

  • 2022-12-23
  • 2021-06-29
  • 2021-12-27
  • 2021-07-10
  • 2022-12-23
  • 2021-11-17
  • 2021-07-27
猜你喜欢
  • 2022-01-03
  • 2022-12-23
  • 2021-12-14
  • 2021-11-08
  • 2021-12-04
  • 2021-12-06
  • 2021-09-21
相关资源
相似解决方案