-1

How can I get this Google map to resize to the bounds of the Polyline bounds?

http://goo.gl/hjOcAx

I think I am correct to use this:

var bounds = new google.maps.LatLngBounds();
    decodedPath.getPath().forEach(function(LatLng) {
    bounds.extend(LatLng);
});
map.setBounds(bounds);

but I also think I am putting it in the wrong place.

  • There is no 'GPolyline.getBounds()' in v3 as there is in v2. Javascript is not my strong point but I would love to find a solution to this – user1194034 Dec 14 '13 at 19:44

1 Answers1

0
  1. decodedPath is a path(not a Polyline) and doesn't have a method getPath(). use:

    decodedPath.forEach(function(LatLng) {
       bounds.extend(LatLng);
    });
    
  2. there is no method setBounds(), use fitBounds() instead.
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
  • Thank you! I have also removed the hard-coded lat and lng fields from the myLatlng variable, and removed the 'center' and 'zoom' properties from the myOptions variable, as the fitBounds() method. Works like a charm :) – user1194034 Dec 14 '13 at 21:45