PHP获取经纬度

#获取百度经纬度(ak=百度ak码)
function addressbaidu($address)//$address:地址
{
    $url='http://api.map.baidu.com/geocoder/v2/?address='.$address.'&output=json&ak=Bsr5iefxHEwQD8iCFTx3GwWOem0ZoSBk';
    if($result=file_get_contents($url))  
    {  
        $arr= explode(',"lat":', substr($result, 40,36));
        return $arr;
    }
}


#获取高德经纬度(key=高德key值)
function addresstolatlag($address){//$address:地址
    $url='http://restapi.amap.com/v3/geocode/geo?key=a5767d2101d83dffcb6cc0325eaccfb4&s=rsv3&city=35&address='.$address;
    if($result=file_get_contents($url))
    {
        $result = json_decode($result,true);
        //判断是否成功
        if(!empty($result['count'])){
            return  explode(',',$result['geocodes']['0']['location']);

        }else{
            return false;
        }

    }
}

 

你可能感兴趣的:(PHP获取经纬度)