我有点问题,
我需要从道路名称(我提供的)获取地点的坐标,我尝试使用file_get_contents
& json_decode
,但其中一些人无法工作(返回带有 ZERO_RESULTS 的stdClass)!
如果我复制粘贴网址(exaclty相同)在浏览器中,它会向我发送正确的数据,不知道原因。
如果我尝试使用另一个道路名称,它就有效。
显然我已经尝试清除缓存,但没有结果,更改导航器也没有工作,也尝试在多台服务器上,但仍然没有结果,尝试使用CURL(as provided as an answer in a post relating the same problem ),但仍然没有结果。
我很失落,我希望你能帮助我。
这里的代码。
提供的数据来自法国道路名称,您可以添加"法国"在$ a中如果你想看到它
数据
// Not Working
$a = "17 bis Les Chaises";
$b = "77510";
// Working
$a = "2 rue Jean Moulin";
$b = "70300";
生成的链接
// Not Working
https://maps.google.com/maps/api/geocode/json?address=17+bis+Les+Chaises+77510
// Working
https://maps.google.com/maps/api/geocode/json?address=2+rue+Jean+Moulin+70300
CURL
$url = "https://maps.google.com/maps/api/geocode/json?address=".str_replace(" ","+",$a)."+".$b;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);
print_r($response_a);
的file_get_contents
$j = json_decode(file_get_contents("https://maps.google.com/maps/api/geocode/json?address=".str_replace(" ","+",$a)."+".$b),true);
print_r("https://maps.google.com/maps/api/geocode/json?address=".str_replace(" ","+",$a)."+".$b);echo "\n\n\n\n\n\n\n";
print_r($j["results"][0]["geometry"]["location"]["lat"].",".$j["results"][0]["geometry"]["location"]["lng"]);
var_dump(file_get_contents("https://maps.google.com/maps/api/geocode/json?address=".str_replace(" ","+",$a)."+".$b));
感谢阅读。
答案 0 :(得分:3)
我发现如果您将+ France添加到您的搜索条件中,则您的非工作请求将无效。
// Not Working
https://maps.google.com/maps/api/geocode/json?address=17+bis+Les+Chaises+77510
// Working
https://maps.google.com/maps/api/geocode/json?address=17+bis+Les+Chaises+77510+France