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?

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top