I'm using the code below to get the route between two points:
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
}
It's working fine, but I don't want to change my map position and zoom level when drawing route. So when I call the code above with different latitude and longitude values, I would like my map position and zoom level to be maintained. Any idea?
When you create the
DirectionsRenderer
api-doc, you can pass aDirectionsRendererOptions
api-doc object to the constructor function or you can call theDirectionsRenderer.setOptions
method if you would like to change the options at some time after creation.You can use the
preserveViewport
property of theDirectionsRendererOptions
object to control how the renderer will interact with the map. SettingpreserveViewport
totrue
will leave the map display unchanged: