Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google map zoom after directions

I am using google maps in order to give some directions from one point to another.

Although, I have set the zoom of the map to 15 the zoom changes after the response of the direction request in order probably to fit the directions into the map.

Does anyone nows how to keep the zoom constant at 15. and focus at the first point?

like image 778
Reven Avatar asked Sep 28 '12 12:09

Reven


People also ask

Can you control the zoom on Google Maps?

Google Maps - The Default Controls Zoom - displays a slider or "+/-" buttons to control the zoom level of the map. Pan - displays a pan control for panning the map.

Why does Google Maps keep zooming out?

To zoom in, always double-left click to zoom in and double-right click to zoom out. If you press the wrong mouse or touchpad button, you'll zoom the wrong way. Correct this problem by zooming back in with the double left-click control.

How do you zoom in and out on the map is done with?

The easiest way to zoom in or out on the map is to use the scroll wheel of your mouse.


1 Answers

See the documentation for the DirectionsRenderer

preserveViewport: true

will prevent the DirectionsRenderer from changing the zoom.

To center the map on the first point use the map.setCenter function. You will need to parse the response from the directions service and create a google.maps.LatLng object for the first point.

This example shows one way to parse the response:

http://www.geocodezip.com/v3_directions_custom_iconsC.html

(you don't need everything, just the location of the point you want to center on)

like image 76
geocodezip Avatar answered Sep 18 '22 05:09

geocodezip