Google GeoCode自动完成限制状态 [英] Google GeoCode Autocomplete limit State

查看:95
本文介绍了Google GeoCode自动完成限制状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将Google Geocode自动填充字段添加到我的表单中。



我已经能够将结果返回给国家(AU)但如果我能将结果限制在国家,情况会更好。 (新南威尔士州/新南威尔士州)



这是我目前的 initialize()函数:

  function initialize(){
var options = {
types:['geocode'],
componentRestrictions:{国家:AU}
};
autocomplete = new google.maps.places.Autocomplete(
(document.getElementById('autocomplete')),options);
google.maps.event.addListener(autocomplete,'place_changed',function(){
fillInAddress();
});
}

我已阅读文档,发现您可以使用类型参数来限制结果,但我一直无法确定确切的代码应该是什么。



只需将其更改为:

 类型:['administrative_area1':'NSW'],// OR'新南威尔士州'

以及与上述类似的各种组合(=而不是:etc)都没有工作..



有人能指出我正确的方向是什么实际的语法是为了我想达到的目的吗?

谢谢。

解决方案

我使用自动完成而没有任何过滤器,但在发送之前自动将我感兴趣的状态追加到所有用户输入查询。



对于想要加利福尼亚州结果的人,例如,如果他们要搜索 Sacramento ,它会自动合作将输入改为加利福尼亚州萨克拉门托,这对我来说有点奏效。您可以对发送的数据更具体,例如美国加利福尼亚州萨克拉门托


I am trying to add an Google Geocode Autocomplete field to my form.

I have been able to get it to restrict the results returned to the country (AU) but it would be even better if I could limit the results to the state as well. (New South Wales/NSW)

This is my current initialize() function:

function initialize() {
var options = {
types: ['geocode'],
    componentRestrictions: {country:"AU"}
};
  autocomplete = new google.maps.places.Autocomplete(
  (document.getElementById('autocomplete')),options);
  google.maps.event.addListener(autocomplete, 'place_changed', function() {
  fillInAddress();
  });
}

I have read the documentation and found that you can use the types parameter to restrict the results, but I have been unable to work out what the exact code should be.

Simply changing it to:

types: ['administrative_area1':'NSW'], // OR 'New South Wales'

and various combinations similar to the above (= instead of : etc) have not worked..

Could someone point me in the right direction towards what the actual syntax is for what I am trying to achieve?

Thanks.

解决方案

I use autocomplete without any sort of filter on it but automatically append the state I'm interested in to all of the user input before sending the query.

For someone who wants California results, for example, if they were to search for Sacramento it would automatically correct the input to Sacramento, California and this has worked somewhat well for me. You could be even more specific with the data you send, for example Sacramento, California, USA

这篇关于Google GeoCode自动完成限制状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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