将自动填充功能添加到Google Geocoder [英] Adding Autocomplete to Google Geocoder

查看:125
本文介绍了将自动填充功能添加到Google Geocoder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我最近的成功(在这里的帮助下)之后,我想完成我的脚本。 Google同意可以将地理编码地图结果放在第二页上,因此我想从第一页的地理编码脚本中删除地图显示。



I在这里工作:
http://jsfiddle.net/njDvn/15/



但是!它唯一没有的是autosuggest(谷歌的一个,而不是一个jqueryUI)。下面是一些代码,它演示了google autosuggest:
http://jsfiddle.net/Rr5PL/63 /



现在,似乎启用autosuggest的代码是这样的:

  var autocomplete = new google.maps.places.Autocomplete(address,options); 
var autocompleteOptions = {types:['geocode']};

我将它添加到了我的原始代码中,并且不幸它不起作用!此代码可以在这里看到:
http://jsfiddle.net/njDvn/16/



所以我的问题是,基于我的原始代码在我的 FIRST LINK ,如何启用Google自动填充建议?



您可以给予的任何帮助或输入将会非常感谢!谢谢。

解决方案

这是 自动填充示例 ,(仅限美国),包含Streetview。 创建它:

  var input = document.getElementById('searchTextField'); 
var options = {
types:[],
componentRestrictions:{country:'us'}
};

var autocomplete = new google.maps.places.Autocomplete(input,options);

您还需要加载Places库:

 < script src =https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places>< / script> 

和HTML:

 < input id =searchTextFieldtype =textsize =50value => 

顺便说一下,您不需要将自动完成功能添加到地理编码器。地理编码功能。

After my recent success (with help from here), I wanted to finish up my script. Google agreed that it was ok to put the geocoded map result on the second page so I want to strip out the map display from my geocoding script on the first page.

I have this working here: http://jsfiddle.net/njDvn/15/

BUT! The only thing it doesnt have is autosuggest (the google one, not a jqueryUI one). Here is some code which does demonstrate the google autosuggest: http://jsfiddle.net/Rr5PL/63/

Now, the code that seems to enable the autosuggest is this:

var autocomplete = new google.maps.places.Autocomplete(address,options);
var autocompleteOptions = {types: ['geocode']};

I added this to my original code and unfortunatly it doesnt work! This code can be seen here: http://jsfiddle.net/njDvn/16/

So my question is, based on my original code in my FIRST LINK, how do I enable the google autocomplete suggestions?

Any help or input you can give would be much appreciated! Thank you.

解决方案

Here is an Autocomplete example, (US only), with Streetview included.

The key lines for creating it are:

var input = document.getElementById('searchTextField');
var options = {
    types: [],
    componentRestrictions: {country: 'us'}
};

var autocomplete = new google.maps.places.Autocomplete(input, options);

You also need to load the Places library:

<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>

and the HTML:

<input id="searchTextField" type="text" size="50" value="">

By the way, you don't "add autocomplete to the geocoder".The Places Autocomplete class includes geocoding capabilities.

这篇关于将自动填充功能添加到Google Geocoder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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