Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

app script map fit markers

//create empty LatLngBounds object
var bounds = new google.maps.LatLngBounds();
var infowindow = new google.maps.InfoWindow();    

for (i = 0; i < locations.length; i++) {  
  var marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map
  });

  //extend the bounds to include each marker's position
  bounds.extend(marker.position);

  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][0]);
      infowindow.open(map, marker);
    }
  })(marker, i));
}

//now fit the map to the newly inclusive bounds
map.fitBounds(bounds);

//(optional) restore the zoom level after the map is done scaling
var listener = google.maps.event.addListener(map, "idle", function () {
    map.setZoom(3);
    google.maps.event.removeListener(listener);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: generate numbers from 1 to 100 to array 
Javascript :: canvas rectangle rounded corners 
Javascript :: leap year function javascript 
Javascript :: angular build production 
Javascript :: react native safeareaview 
Javascript :: get ip address javascript 
Javascript :: webpack-bundle-analyzer react 
Javascript :: sample docker for node js 
Javascript :: text.toUpperCase is not a function 
Javascript :: jquery datatime 
Javascript :: remove duplicate value from array 
Javascript :: filter repetition 2d array javascript 
Javascript :: json stringify 
Javascript :: mongoose findone exclude perticular field 
Javascript :: add array to array js 
Javascript :: npm run build serve 
Javascript :: cors in node js 
Javascript :: using / for division is deprecated and will be removed in dart sass 2.0.0 
Javascript :: change property in array of objects javascript 
Javascript :: my loader is continously loading js 
Javascript :: find property in nested object 
Javascript :: merge 2 array of object by key 
Javascript :: mongodb unwind 
Javascript :: how to convert string to camel case in javascript 
Javascript :: js show element with focus 
Javascript :: how to change favicon dynamic in react js 
Javascript :: sentry ignoreerrors 
Javascript :: innertext 
Javascript :: new variable in loop javascript 
Javascript :: http requests in vue 3 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =