Address suggestions by google maps

前端 未结 3 625
谎友^
谎友^ 2021-02-10 19:15

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 f

相关标签:
3条回答
  • 2021-02-10 19:20

    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.

    0 讨论(0)
  • 2021-02-10 19:21

    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 讨论(0)
  • 2021-02-10 19:32

    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

    0 讨论(0)
提交回复
热议问题