Reputation: 75
I would like to center and autozoom a Map with a dynamic encoded Polyline with API V3.
My encoded Polyine is in trace 1, get from a ASP.net C# server side :
var trace1 = "<%= scriptString %>";
vol = new google.maps.Polyline({
map: map,
strokeColor: '#ff0000',
strokeOpacity: 1.0,
strokeWeight: 3
});
var trace = google.maps.geometry.encoding.decodePath(trace1);
vol.setPath(trace);
var bounds = new google.maps.LatLngBounds();
bounds.getCenter();
map.fitBounds(bounds);
But it doesn't works... it center the map over the North Pacific ocean, and my Polyline is in France...
I don't have any Javascript error. Any idea ?
Upvotes: 1
Views: 1056
Reputation: 24419
You'll need to extend the bounds to include the points on your path.
var bounds = new google.maps.LatLngBounds();
vol.getPath().forEach(function(LatLng) {
bounds.extend(LatLng);
});
map.fitBounds(bounds);
Upvotes: 2