3

I have a collection of markers which all show in the correct place on my map. I then use the following code to set the bounds of the map so all markers are visisble.

bounds = new maps.LatLngBounds();

angular.forEach($scope.places, function(place) {
    bounds.extend(new maps.LatLng(place.getLatitude(), place.getLongitude()));
});

console.log(bounds);
map.fitBounds(bounds);
console.log(map.getBounds());

However the map ends up in some random spot where there are no markers at all. The console.log shows the bounds set are not quite the same as the bounds that are returned from getBounds().

// var bounds;
j: 40.793571
k: 40.715086

va: ih
j: -74.00108699999998
k: -73.951866

and

// getBounds();
j: 40.828484316202136
k: 40.68011306824231

j: -74.09878523107909
k: -73.85416776892089
Ben_hawk
  • 2,476
  • 7
  • 34
  • 59
  • Relevant question with good answers: http://stackoverflow.com/questions/19304574/center-set-zoom-of-map-to-cover-all-markers-visible-markers – Kay_N Apr 24 '15 at 00:46

0 Answers0