PHP根据城市名获取经纬度
/**
- 根据城市名获取经纬度
- @param 城市名 $city
- @return mixed
- http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding
*/
public function get_geo($city){
$url = "http://api.map.baidu.com/geocoder/v2/?ak=wfVfdMthZRL9vjaeyFKiBhLmUth60bbZ&output=json&address=$city";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$result = curl_exec($ch);
/* if(curl_errno($ch)){
print_r(curl_error($ch));
} */
curl_close($ch);
return json_decode($result,TRUE);
}