最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there a way to override the Google Directions service zoom values? - Stack Overflow

programmeradmin5浏览0评论

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?

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?

Share Improve this question edited May 28, 2012 at 20:53 Sean Mickey 7,7162 gold badges33 silver badges58 bronze badges asked May 28, 2012 at 9:22 AsrafAsraf 3331 gold badge10 silver badges24 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 16

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);
    }
}

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);
发布评论

评论列表(0)

  1. 暂无评论