admin管理员组文章数量:1432613
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: /
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: /
Now, the code that seems to enable the autosuggest is this:
var autoplete = new google.maps.places.Autoplete(address,options);
var autopleteOptions = {types: ['geocode']};
I added this to my original code and unfortunatly it doesnt work! This code can be seen here: /
So my question is, based on my original code in my FIRST LINK, how do I enable the google autoplete suggestions?
Any help or input you can give would be much appreciated! Thank you.
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/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/Rr5PL/63/
Now, the code that seems to enable the autosuggest is this:
var autoplete = new google.maps.places.Autoplete(address,options);
var autopleteOptions = {types: ['geocode']};
I added this to my original code and unfortunatly it doesnt work! This code can be seen here: http://jsfiddle/njDvn/16/
So my question is, based on my original code in my FIRST LINK, how do I enable the google autoplete suggestions?
Any help or input you can give would be much appreciated! Thank you.
Share Improve this question edited Nov 3, 2012 at 17:38 Jimmy asked Nov 3, 2012 at 17:29 JimmyJimmy 12.5k29 gold badges114 silver badges206 bronze badges3 Answers
Reset to default 3Here is an Autoplete example, (US only), with Streetview included.
The key lines for creating it are:
var input = document.getElementById('searchTextField');
var options = {
types: [],
ponentRestrictions: {country: 'us'}
};
var autoplete = new google.maps.places.Autoplete(input, options);
You also need to load the Places library:
<script src="https://maps.googleapis./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 autoplete to the geocoder".The Places Autoplete class includes geocoding capabilities.
The JavaScript Autoplete is part of the Google Places API, which is not loaded by default with the Google Maps API. You need to explicitly load the Places library when you include the Maps API by adding the parameter libraries=places
:
<script src="http://maps.googleapis./maps/api/js?libraries=places&sensor=false"></script>
Have a look at this ready demo, that does exactly what is mentioned by Marcelo and ssorallen http://devfestmtm.appspot./demos/places/autoplete_addressform.html
本文标签: javascriptAdding Autocomplete to Google GeocoderStack Overflow
版权声明:本文标题:javascript - Adding Autocomplete to Google Geocoder - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745586900a2664962.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论