首页 > 解决方案 > 谷歌在Firefox浏览器中放置错误

问题描述

我使用 google-places-autocomplete 填充字段地址(地址、城市、国家/地区、邮政编码、纬度、经度).. 它在所有浏览器中都能正常工作,但并非每次在 firefox 浏览器中都能正常工作(可能是由缓存引起的firefox浏览器)代码js:

        function initializeAutocomplete(id) {
                    var element = document.getElementById(id);
                    if (element) {
                        var autocomplete = new google.maps.places.Autocomplete(element, { types: ['geocode'], language : _mpop.current_lang });
                        if(id == "parent_personal_info_fullAddress" || id == "edit_babysitter_personal_info_fullAddress" ||
                            id == "address_bb" || id == "home_address" ){
                            google.maps.event.addListener(autocomplete, 'place_changed', onPlaceChangedEditUser);
                        }
                    }
                }


        function onPlaceChangedEditUser(){
        var place = this.getPlace();
        $('.postal_code').val('');
        for (var i in place.address_components) {
            var component = place.address_components[i];
            for (var j in component.types) {
                var type_element = $('.'+component.types[j]);
                if(component.types[j] == "country"){
                    $('#country').find('option').attr('selected', false);
                    $('#country').find('option[data-country="' + component.short_name + '"]').attr('selected', true);
                    $('#country_iso').val(component.short_name);
                    $('#country').change();
                    $('.country-short').val(component.short_name);


                }
                if (type_element) {
                    type_element.val(component.long_name);
                }
                if($("#latitude").length){
                    $("#latitude").val(place.geometry.location.lat());
                    $("#longitude").val(place.geometry.location.lng());

                }
                if($(".latitude").length){
                    $(".latitude").val(place.geometry.location.lat());
                    $(".longitude").val(place.geometry.location.lng());
                }


            }
        }
    }

$(document).ready(function () {
google.maps.event.addDomListener(window, 'load', function() {
    initializeAutocomplete('babysitter_search_address');
});
}

标签: javascriptjquerygoogle-mapsautocompletegoogle-places-api

解决方案


如果您指的是地图图块有时无法加载,这是最近在 Google 问题跟踪器中报告的一个已知问题:

https://issuetracker.google.com/issues/138267513

它似乎已在 v68.0.2 中修复。如果由于某种原因您还不能更新,那么您可以通过关闭 Firefox 的缓存来解决这个问题。

请参阅另一个 SO 线程:Embedded Google Maps tile not loading in Firefox second page load until zoomed

希望这能澄清你的问题。


推荐阅读