我使用此功能获取任何地址的坐标:
function getCoordinates($address) {
$address = str_replace(" ", "+", $address); // replace all the white space with "+" sign to match with google search pattern
$address = str_replace("-", "+", $address); // replace all the "-" with "+" sign to match with google search pattern
$url = "http://maps.google.com/maps/api/geocode/json?address=$address";
$response = file_get_contents($url);
$json = json_decode($response,TRUE); //generate array object from the response from the web
return ($json['results'][0]['geometry']['location']['lat'].",".$json['results'][0]['geometry']['location']['lng']);
}
有时它会起作用,有时它只能得到","对于同一地址。
我需要使用其他功能吗?
答案 0 :(得分:0)
试试这个
$ url =" http://maps.google.com/maps/api/geocode/json?address="。$ address;