Reputation: 287
I have managed to modify a script I found to suite my needs.
my only current issue is that I have to set the center of the map manually in the code and the zoom level.
how can I modify this so the api automatically selects the correct zoom level and center point for the map.
fiddle is here
I need to remove this manual code:
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(-30.559, 22.937),
zoom: 4
}),
and configure it to zoom and center automatically based on the routes given (routes array)
you will see in the fiddle that the costa rica route is off the map so zoom needs to go out. if it was a short trip then zoom in to fit all contents into the map
Thanks as always:
Upvotes: 0
Views: 934
Reputation: 11258
You cannot get rid of that code. Option center
and zoom
are the only required parameters of google.maps.MapOptions
object. See docs of MapOptions.
You can get rid of option preserveViewport
or set it to false
instead of true
so your map will be centered and properly zoomed.
Upvotes: 1