Override Google Maps Directions Zoom

3.1k views Asked by At

I am trying to over-ride Google Maps driving directions zoom. Yes, I have seen another question here on stackoverflow that is identical; however, that solution is not working for me.

Here is where I call a new DirectionsRenderer, and I define preserveViewport: true;

var dr = new google.maps.DirectionsRenderer({
  map: map,
  draggable: false,
  preserveViewport: true
});

Here is where I call the routing service, and I define setOptions preserveviewport:true;

 ds.route({
  origin: from,
  destination: to,
  travelMode: mode
}, function(result, status) {
  if (status == google.maps.DirectionsStatus.OK) {
      fitBounds = true;
      dr.setOptions({ preserveViewport: true });
      dr.setDirections(result);
    }
}); 

However, this is not overriding the zoom functionality of directions service. Thoughts?

2

There are 2 answers

0
SMPLGRP On BEST ANSWER

I solved this. Instead of calling map.fitbounds, I used map.setZoom. Fitbounds is to fit all the points on the screen, at the maximum zoom level. setZoom allows you to set your own zoom.

0
Sreenath Reddy On

I've replaced fitBounds with map.setZoom() , if i set preserveViewport as true, then my map is not visible.