Is there a way to override the scaling values โ€‹โ€‹of the Google Directions service?

I use 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 works fine, but I do not want to change my map position and zoom level when drawing a route. Therefore, when I call the code above with different latitude and longitude values, I would like my map position and zoom level to be supported. Any ideas?

+6
source share
2 answers

When you create the DirectionsRenderer api-doc , you can pass the DirectionsRendererOptions api-doc for the constructor function, or you can call the DirectionsRenderer.setOptions method if you want to change the settings for some time after creation.

You can use the preserveViewport property of the DirectionsRendererOptions object to control how the renderer interacts with the map. Setting preserveViewport to true will leave the map display unchanged:

 directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setOptions({ preserveViewport: true }); directionsDisplay.setDirections(response); } } 
+14
source

This causes the error to stop displaying, but the route does not look good, it looks like some data is missing:

 directionsDisplay.setOptions({ preserveViewport: true }); directionsDisplay.setDirections(response); 
0
source

Source: https://habr.com/ru/post/916826/


All Articles