Google自动填充功能不起作用如何解决?

时间:2017-05-18 13:14:37

标签: javascript jquery google-maps

var placeSearch, autocomplete;
    var componentForm = {
        street_number: 'short_name',
        route: 'long_name',
        locality: 'long_name',
        administrative_area_level_1: 'short_name',
        country: 'long_name',
        postal_code: 'short_name'
    };

    function initialize1() {
        // Create the autocomplete object, restricting the search
        // to geographical location types.
        autocomplete = new google.maps.places.Autocomplete(
            /** @type {HTMLInputElement} */
            (document.getElementById('cityzip')), {
                types: ['geocode']
            });
        // When the user selects an address from the dropdown,
        // populate the address fields in the form.
        google.maps.event.addListener(autocomplete, 'place_changed', function() {
            console.log(autocomplete.getPlace().geometry.location);
        });
    }

请帮助我为什么它不显示自动建议以及为什么它不在控制台中显示lat和long。我怎么解决这个问题请帮助我。对不起语法和拼写错误。

1 个答案:

答案 0 :(得分:0)

可能是你不包括谷歌地图javascript正确。请包括地方图书馆 示例:

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

您可以按以下方式检查地点库:console.log(google.maps.places); 这是jsfiddle.net上的示例。 我希望它对你有所帮助。

https://jsfiddle.net/upsidown/GVdK6/

https://jsfiddle.net/user2314737/f9akomrd/