谷歌地图API自动完成限制/偏见到我的城镇街道地址 [英] Google map api autocomplete restricted/bias to street address in my town

查看:128
本文介绍了谷歌地图API自动完成限制/偏见到我的城镇街道地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为uni编写我的最后一年项目的Web应用程序,我需要解决的第一个问题是获取本地地址输入的自动完成文本框。我花了一些时间在网上浏览,花了一些时间玩谷歌地图V3的地方自动完成插件。



有一些我不太理解api文档哪些我希望有人能够为我清理,也可能指向正确的方向。



在文档中说明了这一点:

$ (区域)类型集合指示Place服务返回任何匹配以下类型的结果:

$ b
$ b



$ b

  locality 
sublocality
postal_code
country
administrative_area1
administrative_area2
code>

这是我目前不明白的地方,我住在康沃尔郡(确切地说,博德明),我想让结果偏向于博德明。我完成了以下工作:

  var input = document.getElementById('inputOne'); 
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(50.423394,-4.803829),
google.maps.LatLng(50.508623,-4.692593));

//需要设置界限到cornwall / bodmin
var options = {
界限:defaultBounds,
类型:['geocode'],
componentRestrictions:{country:'GB'}
};
var autocomplete = new google.maps.places.Autocomplete(input,options);

现在这个方法可行,但如果我输入st n,我预计它会首先出现与在博德明的st nicolas街道。但它会提出像几英里远的st neot这样的东西。

有一部分人认为我需要将类型设置为不同的值,但我现在非常难过。



编辑:
我想要实现的示例是在maps.google.com页面上,如果您输入,博德明然后在逗号前移动光标,开始输入街道名称,甚至是Asda,它将保持它在本地区的位置。我宁愿不必输入博德明,但这是我可以解决的问题。如果任何人有任何想法,那将是非常棒的。

那么我需要弄清楚用户可以如何放置一些值,如Asda并获取本地asda地址。

解决方案

目前不可能将结果限制在特定位置,除了像上面所做的那样使用边界。然而,这只会将结果偏向于,但不限于指定范围内的地点。



如果您认为按地区划分的结果是一项有用的功能,请将 Places API - 功能请求
$ b

正如你所提到的,如果你在查询结尾键入,Bodmin 可能会返回当地的结果。临时解决方案可能是使用 AutocompleteService 并追加,Bodmin getPlacePredictions()请求输入参数的末尾。


I am trying to write a web application for my final year project at uni, and one of the first problems i need to tackle is getting an auto complete text box for local address input. i have spent some time looking around the internet and spent some time playing with the google maps V3 places autocomplete plugin.

there is something i dont quite understand on the api docs which i was hoping someone might be able to clear up for me, aswell as maybe point me in the right direction.

in the docs it says this:

the (regions) type collection instructs the Place service to return any result matching the following types:

locality
sublocality
postal_code
country
administrative_area1
administrative_area2

this is what i currently dont understand, i live in cornwall (bodmin to be exact) and i want to make the results bias to bodmin. i have done the following:

var input = document.getElementById('inputOne');
var defaultBounds = new google.maps.LatLngBounds(
  new google.maps.LatLng(50.423394,-4.803829),
  new google.maps.LatLng(50.508623,-4.692593));

        //need to set bounds to cornwall/bodmin
        var options = {
            bounds: defaultBounds,
          types: ['geocode'],
          componentRestrictions: {country: 'GB'}
        };
var autocomplete = new google.maps.places.Autocomplete(input,options);

now this works but if for example i enter "st n" i would expect it to first come up with st nicolas street which is in bodmin. but it will come up with things like st neot which is several miles away.

there is part of me that thinks that i need to set the type to a different value, but i am pretty stumped right now.

EDIT: Example of what i am trying to achieve is on the maps.google.com page if you enter ,Bodmin then move the cursor before the comma and start to type a street name or even Asda it will keep it local to what is in that area. i would prefer not to have to type the ,bodmin but that is something which i could work around

if anyone has any ideas that would be awesome. then i will need to figure out how the user can put in some values like "Asda" and get the local asda address.

解决方案

It is currently not possible to restrict results to a specific locality except for using bounds as you have done so above. This however, only biases results towards, but not restricted to places contained within the specified bounds.

If you believe result by locality would be a useful feature please file a Places API - Feature Request.

As you mentioned, if you type ,Bodmin at the end of your query it is more likely to return local results. A temporary solution might be to use the AutocompleteService and append ,Bodmin to the end of the getPlacePredictions() requests input parameter.

这篇关于谷歌地图API自动完成限制/偏见到我的城镇街道地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆