开发者

Address suggestions by google maps

开发者 https://www.devze.com 2023-03-26 14:53 出处:网络
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?

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 writ开发者_高级运维es 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


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.


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


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消