HTTP 身份验证是否会妨碍服务器端 Google 地图反向地理编码 API 调用
在我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您的服务器正在进行调用,因此问题不应该与身份验证有关。我的猜测是,它是您的
sensor=true_of_false
,应该是sensor=true
或sensor=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 besensor=true
orsensor=false
. Another possibility is your key is IP restricted in someway. Check the developer console.