Google Maps Api v3 - getBounds is undefined

前端 未结 5 1688
春和景丽
春和景丽 2020-11-30 21:41

I\'m switching from v2 to v3 google maps api and got a problem with gMap.getBounds() function.

I need to get the bounds of my map after its initializati

5条回答
  •  情深已故
    2020-11-30 22:14

    It should be working, atleast according to the documentation for getBounds(). Nevertheless:

    var gMap;
    $(document).ready(function() {
        var latlng = new google.maps.LatLng(55.755327, 37.622166);
        var myOptions = {
            zoom: 12,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        gMap = new google.maps.Map(document.getElementById("GoogleMapControl"), myOptions);
        google.maps.event.addListenerOnce(gMap, 'idle', function(){
            alert(this.getBounds());
        });
    });
    

    See it working here.

提交回复
热议问题