Google MAP API v3: Center & Zoom on displayed markers

后端 未结 4 853
囚心锁ツ
囚心锁ツ 2020-11-29 01:12

I use the following code to set markers on my map:

  var latLngs = []
  $.each(locations.markers, function(i, m){
   var myLatLng = new google.maps.LatLng(m.         


        
4条回答
  •  无人及你
    2020-11-29 01:40

    for center and auto zoom on display markers

    // map: an instance of google.maps.Map object
    
    // latlng_points_array: an array of google.maps.LatLng objects
    
    var latlngbounds = new google.maps.LatLngBounds( );
    
        for ( var i = 0; i < latlng_points_array.length; i++ ) {
            latlngbounds.extend( latlng_points_array[i] );
        }
    
    map.fitBounds( latlngbounds );
    

提交回复
热议问题