Frage

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.

War es hilfreich?

Lösung

  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.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top