有没有办法覆盖Google路线服务缩放值? [英] Is there a way to override the Google Directions service zoom values?
问题描述
directionsService.route(request,function(响应,状态){
if(status == google.maps.DirectionsStatus.OK){
directionsDisplay.setDirections(response);
}
}
工作正常,但我不想在绘制路线时更改地图位置和缩放级别。代码上面有不同的经度和纬度值,我想我的地图位置和缩放级别保持。
任何想法?
当您创建 DirectionsRenderer
api-doc ,您可以传递 DirectionsRendererOptions
api-doc 对象到c你可以调用 DirectionsRenderer.setOptions
方法,如果你想在创建后的某个时候改变选项。
您可以使用 DirectionsRendererOptions
对象的 preserveViewport
属性来控制渲染器如何与地图交互。将 preserveViewport
设置为 true
会使地图显示保持不变:
directionsService.route(request,function(response,status){
if(status == google.maps.DirectionsStatus.OK){
directionsDisplay.setOptions( {preserveViewport:true});
directionsDisplay.setDirections(response);
}
}
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?
When you create the DirectionsRenderer
api-doc, you can pass a DirectionsRendererOptions
api-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 true
will leave the map display unchanged:
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setOptions({ preserveViewport: true });
directionsDisplay.setDirections(response);
}
}
这篇关于有没有办法覆盖Google路线服务缩放值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!