PHP get latitude and longitude [API] Baidu map by address

/ * * 
 * @Param address Address String $ 
 * @param string $ city City 
 * @return Array 
 * / 
function getLatLng ( $ address = '', $ City = '' ) 
{ 
    $ Result = Array ();
     $ AK = ''; // your Baidu map ak, you can go to Baidu Developer Center free to apply for 
    $ 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'];
        returns the latitude and longitude result//;$ the Resultreturn 
    }else{
        return null;
    }
 
}

From the micro-channel public number: Programming Society

Advanced programmers daily book, please pay attention!

Guess you like

Origin www.cnblogs.com/ai10999/p/11449476.html