Is there a way to override the Google Directions service zoom values?

落花浮王杯 提交于 2020-01-02 03:19:10

问题


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?


回答1:


When you create the DirectionsRendererapi-doc, you can pass a DirectionsRendererOptionsapi-doc object to the constructor function or you can call the DirectionsRenderer.setOptions method if you would like to change the options at some time after creation.

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

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



回答2:


This makes the error stop showing, but still the route doesn't draw well, looks like there is some data missing:

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


来源:https://stackoverflow.com/questions/10782218/is-there-a-way-to-override-the-google-directions-service-zoom-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!