gpt4 book ai didi

PHP - Google Maps API 搜索返回 ZERO_RESULTS 但 Navigator 显示它

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:40:34 25 4
gpt4 key购买 nike

我有点问题,

我需要从道路名称(我提供的)中获取地点的坐标,我尝试使用 file_get_contentsjson_decode 来实现,但是一些其中的一个不起作用(返回一个带有 ZERO_RESULTS 的 stdClass)!

如果我在浏览器中复制粘贴 url(完全相同),它会向我发送正确的数据,不知道为什么

如果我尝试使用另一个道路名称,它会起作用。

显然我已经尝试清除缓存,但没有结果,更改导航器也不起作用,也在多台服务器上尝试过,但仍然没有结果,尝试使用 CURL ( as provided as an answer in a post relating the same problem),但仍然, 没有结果。

我很迷茫,我希望你能帮我解决这个问题。

这里是代码。

提供的数据来自法国路名,想看的可以在$a中加上“France”

数据

// 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));

感谢阅读。

最佳答案

我发现如果您将 +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

关于PHP - Google Maps API 搜索返回 ZERO_RESULTS 但 Navigator 显示它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42957948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com