Google Maps API V3: Show the whole world

后端 未结 5 1395
小蘑菇
小蘑菇 2020-12-08 11:25

How can I programmatically zoom the map so that it covers the whole world?

5条回答
  •  無奈伤痛
    2020-12-08 11:54

    function initialize () {
    
    var mapOptions = {
    	center: new google.maps.LatLng(0, 0),
    	zoom: 1,
    	minZoom: 1
    };
    
    var map = new google.maps.Map(document.getElementById('map'),mapOptions );
    
    var allowedBounds = new google.maps.LatLngBounds(
    	new google.maps.LatLng(85, -180),	// top left corner of map
    	new google.maps.LatLng(-85, 180)	// bottom right corner
    );
    
    var k = 5.0; 
    var n = allowedBounds .getNorthEast().lat() - k;
    var e = allowedBounds .getNorthEast().lng() - k;
    var s = allowedBounds .getSouthWest().lat() + k;
    var w = allowedBounds .getSouthWest().lng() + k;
    var neNew = new google.maps.LatLng( n, e );
    var swNew = new google.maps.LatLng( s, w );
    boundsNew = new google.maps.LatLngBounds( swNew, neNew );
    map .fitBounds(boundsNew);
    
    }
    
    google.maps.event.addDomListener(window, 'load', initialize);
    #map {
        width: 500PX;
        height: 500px;
    }
    
      
       
      
      
      
        

    // map zoom level should be 1
    

提交回复
热议问题