使用 Google 地图进行区域偏差
我的用户可能位于世界任何地方,他们都会看到一个文本框,他们可以在其中输入他们的地址。在大多数情况下,我假设他们实际上与他们输入的地址位于同一个国家/地区。
谢谢。
My users, who may be located anywhere in the world, will be presented with a text box wherein they can enter their address. In most cases, I assume they will physically be in the same country as whatever address they are typing.
I'd like to help Google Map API make better guesses by doing region biasing. Is there a way to tell Google to region bias from where the request is being made? Or how can I give that information to Google when I make the web service call (e.g. convert IP address to country information)?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上次我检查时,客户端和服务器端 Google Geocoder 的“区域偏差”都不可靠。查看去年四月的这篇文章(现在再次测试,问题仍然存在):
我发现最可靠的方法是将国家/地区附加在地址末尾。因此,如果用户位于英国,并输入“伦敦牛津街”,您需要将“, UK”附加到地址以进行地理编码。
要获取用户所在的国家/地区,有很多解决方案。您可以使用 Geolocation API按照 @You 在其他答案中的建议 ,或者您可能想要使用第三方 IP 定位服务。您可能需要查看 MaxMind GeoLite City 服务,该服务是免费的,据报道 99.5%在国家层面上准确。
The last time I checked, the "region bias" for both the client-side and the server-side Google Geocoder was not reliable. Check out this post from last April (tested again right now, and the issue persists):
The most reliable way that I found is to append the country at the end of the address. Therefore if the user is located in the UK, and types "Oxford Street London", you'd attach ", UK" to the address for geocoding.
To get the country of the user, there are quite a few solutions. You could use the Geolocation API as @You suggested in the other answer, or you may want to use a third party IP-to-location service. You may want to check out MaxMind GeoLite City service, which is free, and is reportedly 99.5% accurate on a country level.
在现代浏览器中,您可以使用 HTML5 地理定位 API,如深入了解 HTML5 中所述。这假设有客户端支持并且您在客户端发出请求。对于服务器端(或后备)解决方案,您可以尝试类似 PHP Geo IP 函数。
In modern browsers you can use the HTML5 Geolocation API as described in Dive Into HTML5. This assumes client-side support and that you're making the requests client-side. For a server-side (or fallback) solution, you could try something like the PHP Geo IP functions.