HTTP 身份验证是否会妨碍服务器端 Google 地图反向地理编码 API 调用

发布于 2025-01-07 11:05:10 字数 556 浏览 0 评论 0原文

在我的 php 应用程序中,我使用谷歌的反向地理编码服务。它在 localhost 上运行良好,其中 url 是 myproject.ryan.com。但是,如果我在临时服务器上进行测试,该服务器位于 IP 地址(我们还没有域)并且具有 HTTP 身份验证密码保护,则反向地理编码不起作用。这是相同的代码,所以我猜这一定与 IP 的使用或身份验证提示有关。我想知道我是否需要在控制台中执行某些操作。

代码...

// Format this string with the appropriate latitude longitude.
$url = 'http://maps.google.com/maps/geo?q=' . $latlng . '&output=json&sensor=true_or_false&key=' . APP_KEY;

// Make the HTTP request.
$data = @file_get_contents($url);

// Parse the json response.
$jsondata = json_decode($data,true);

In my php app I use google's reverse geocoding service. It works fine on localhost, where the url is myproject.ryan.com. But if I test on the staging server, which is at an IP address (we have no domain yet) and has HTTP auth password protection, the reverse geocoding doesn't work. It's the same code, so this must be related to either the use of IP or the auth prompt, I would guess. I wonder if there is something I need to do in the console.

The code...

// Format this string with the appropriate latitude longitude.
$url = 'http://maps.google.com/maps/geo?q=' . $latlng . '&output=json&sensor=true_or_false&key=' . APP_KEY;

// Make the HTTP request.
$data = @file_get_contents($url);

// Parse the json response.
$jsondata = json_decode($data,true);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

计㈡愣 2025-01-14 11:05:10

由于您的服务器正在进行调用,因此问题不应该与身份验证有关。我的猜测是,它是您的 sensor=true_of_false,应该是 sensor=truesensor=false。另一种可能性是您的密钥在某种程度上受到 IP 限制。检查开发者控制台。

Since your server is making the call, the problem shouldn't be with the authentication. My guess is that it is your sensor=true_of_false, should be sensor=true or sensor=false. Another possibility is your key is IP restricted in someway. Check the developer console.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文