Google Autocomplete API - format output result

后端 未结 2 1377
时光说笑
时光说笑 2021-01-20 04:22

I\'m trying to implement Google Places API, so here is my code:




    

        
相关标签:
2条回答
  • 2021-01-20 05:04

    I was able to solve my problem with the following code:

    $(document).ready(function() {
         var el = $('#street').attr("placeholder", "")
            , autocomplete = new google.maps.places.Autocomplete( ( el.get(0) ), { types: ['geocode'] } );
    
            el.bind("blur", function() {
              el.css("color", "#fff"); // this will prevent text flashing
            })
    
            google.maps.event.addListener(autocomplete, 'place_changed', function() {
               var place = autocomplete.getPlace();
    
                el.val(place.name);
    
                // this will override default Google suggestion
                setTimeout(function() {
                    el.val(place.name);
                    el.css("color", "");
                }, 0)
            });
    })
    
    0 讨论(0)
  • 2021-01-20 05:18

    you can get by

    el.get(0).getLocality()
    
    0 讨论(0)
提交回复
热议问题