繁体   English   中英

谷歌地图不呈现模式弹出

[英]google maps not rendering on modal popup

下面是我的jQuery代码,我正在使用部分视图在模态弹出窗口上渲染谷歌地图。

地图本身不会呈现,如果我调整浏览器窗口的大小或检查浏览器时会呈现(与窗口调整大小相同)。

同样,当根据“纬度-经度”设置将其渲染为不在中心时。

我想基于隐藏字段中设置的纬度-经度来动态渲染地图。 目前,我正在传递的纬度= 30.704648600和经度= 76.717872600。

TIA,我不知道缺少什么,请帮忙。

jQuery的:-

    $(document).ready(function () {
        var currLoc;
        if ($('#Latitude').val().length > 0 && $('#Longitude').val().length > 0)
            initialize($('#Latitude').val(), $('#Longitude').val());
    });

    function initialize(Latitude, Longitude) {
        var latlng = new google.maps.LatLng(Latitude, Longitude);
        var map = new google.maps.Map(document.getElementById('map_'), {
            center: latlng,
            zoom: 13
        });
        var marker = new google.maps.Marker({
            map: map,
            position: latlng,
            draggable: false,
            //anchorPoint: new google.maps.Point(0, -29)
        });
        map.setCenter(new google.maps.LatLng(Latitude, Longitude));

        var infowindow = new google.maps.InfoWindow();
        currLoc= $('#lastLocation').text();
        google.maps.event.addListener(marker, 'click', function () {
            var iwContent = '<div id="iw_container">' +
            '<div class="iw_title"><b>Last Location</b> : <span class="lastLoc">' + GetAddress(Latitude, Longitude) + '<span></div></div>';               
            infowindow.setContent(iwContent);               
            infowindow.open(map, marker);
        });
    }

    function GetAddress(Latitude, Longitude) {
        var LastLatLong = [];
        LastLatLong.push([Latitude, Longitude]);
        var latlngArray_ = LastLatLong[0];
        var latlngset_ = new google.maps.LatLng(latlngArray_[0], latlngArray_[1]);
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode({ 'latLng': latlngset_ }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                if (results[0]) {
                    //currLoc= results[0].formatted_address;
                    if ($('.lastLoc').length > 0) {
                        debugger;
                        $('.lastLoc').text(results[0].formatted_address);
                    }
                }
            }
        });
    }

我得到了答案,可以先触发地图的resize事件,然后使用其setCenter属性来完成。

我现在更改了初始化函数,它的工作正常。

function initialize(Latitude, Longitude) {
        var latlng = new google.maps.LatLng(Latitude, Longitude);
        var map = new google.maps.Map(document.getElementById('map_'), {
            center: latlng,
            zoom: 13
        });
        var marker = new google.maps.Marker({
            map: map,
            position: latlng,
            draggable: false,
            //anchorPoint: new google.maps.Point(0, -29)
        });
        map.setCenter(new google.maps.LatLng(Latitude, Longitude));

        var infowindow = new google.maps.InfoWindow();
        currLoc= $('#lastLocation').text();
        google.maps.event.addListener(marker, 'click', function () {
            var iwContent = '<div id="iw_container">' +
            '<div class="iw_title"><b>Last Location</b> : <span class="lastLoc">' + GetAddress(Latitude, Longitude) + '<span></div></div>';               
            infowindow.setContent(iwContent);               
            infowindow.open(map, marker);
        });
  setTimeout(function () {
            google.maps.event.trigger(map, "resize");
            map.setCenter(new google.maps.LatLng(Latitude, Longitude));
        }, 300);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM