Google 地图 API 自动完成功能仅绑定到英国
可能的重复:
将 Google 地图自动填充功能仅限于英国地址
如果任何人使用 Google地图 API V3 的经验可以帮助我,我将不胜感激 - 我已经在这方面坚持了几个小时了。
我试图让我的自动完成功能仅返回英国地址(因为该网站位于英国),但我的代码无法正常工作,即使它看起来好像我做得正确。我仍然收到所有其他国家的建议。
这是我的自动完成代码:
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-0.12800500000003012, 51.508129),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(49.00, -13.00),
new google.maps.LatLng(60.00, 3.00));
var input = document.getElementById('sei');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.setBounds(bounds);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
我不确定从哪里获取边界 - 我在论坛上找到了上面的代码,但不确定它们是否 100% 正确。
下面是我的 API 包括:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=places,geometry&sensor=false®ion=GB&gl=gb"></script>
如您所见,我在查询字符串中设置了区域和 gl。如果您看到下面的图片,您就会看到我的结果。是的,它稍微偏向英国 - 但仍然有洛杉矶出现。
任何帮助将不胜感激!
Possible Duplicate:
limiting google maps autocomplete to UK address only
If anyone with Google Maps API V3 experience can help me out it would be much appreciated - I've been stuck on this for hours.
I'm trying to get my autocomplete to return UK addresses only (because the site is based in the UK), but my code isn't working even though it appears as though I've done it right. I still get all other countries as suggestions.
Here's my autocomplete code:
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-0.12800500000003012, 51.508129),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(49.00, -13.00),
new google.maps.LatLng(60.00, 3.00));
var input = document.getElementById('sei');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.setBounds(bounds);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
I'm not sure where to get bounds from - I have found the ones above on a forum but am not sure if they're 100% correct.
Below is my API include:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=places,geometry&sensor=false®ion=GB&gl=gb"></script>
As you can see I have set a region and gl in the querystring. If you see my image below, you'll see the result I have. Yes, it's slightly more biased to the UK - but there's still Los Angeles appearing.
Any help would be much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请记住,自动完成类中的
setBounds()
方法 将设置返回地点结果的首选区域。结果偏向但不限于该领域。Bear in mind that the
setBounds()
method in the Autocomplete class will set the preferred area within which to return Place results. Results are biased towards, but not restricted to, this area.您使用的边界似乎是错误的。试试这些:
(49.383639452689664,-17.39866406249996)
(59.53530451232491,8.968523437500039)
You're using the wrong bounds it appears. Try these out:
(49.383639452689664, -17.39866406249996)
(59.53530451232491, 8.968523437500039)