【发布时间】:2018-05-03 12:36:17
【问题描述】:
我正在使用这个函数来获取任意地址的坐标:
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']);
}
有时它有效,有时它只为同一地址获得“,”。
我需要使用其他功能吗?
【问题讨论】:
-
您是否尝试在您的函数中记录您的 $address ?因此,您可以了解您的价值究竟在哪里转向“,”。
标签: php function maps coordinates