Address suggestions by google maps

我怕爱的太早我们不能终老 提交于 2019-11-30 14:17:29

问题


Does somebody know if there is any way to reproduce an ajax suggestion box like http://maps.google.com/ have in my webpage using the google maps api?

The idea would be for example if somebody writes down "15 Avenue" a list of suggestions:

"15 Avenue of the Americas, New York, NY, United States"

"15 Avenue of the Stars, Los Angeles, CA, United States"

Etc

Just a yes no qustion =)

Thanks


回答1:


Yes.

Look at the geocode response for "15 Avenue"...

http://maps.googleapis.com/maps/api/geocode/json?address=15+Avenue&sensor=false

You get a list of possible results that you can put in a dropdown.




回答2:


There is an API example from Google.

Make sure you load the places library:

<script type="text/javascript"
    src="https://maps.googleapis.com/maps/api/js?v=3&libraries=places">
</script>

Next your javascript:

var autocomplete;
function initialize() {
    autocomplete = new google.maps.places.Autocomplete(
        document.getElementById('autocomplete'),
        { types: ['geocode'] }
    );
}
google.maps.event.addDomListener(window, 'load', initialize);

With HTML

<div><input id="autocomplete" type="text"></div>

Also see https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform




回答3:


I found this on another answer on stackoverflow. This page shows how to provide autocomplete choices using google maps/geocoding.

http://tech.cibul.net/geocode-with-google-maps-api-v3/



来源:https://stackoverflow.com/questions/6989428/address-suggestions-by-google-maps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!