Google Autocomplete API - format output result

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 15:12:18

you can get by

el.get(0).getLocality()

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