我使用下面的代码来获取两点之间的路线:
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
}
它工作正常,但我不想在绘制路线时更改地图位置和缩放级别。因此,当我使用不同的纬度和经度值调用上面的代码时,我希望保持我的地图位置和缩放级别。
任何想法?
When you create the DirectionsRenderer
api-doc https://developers.google.com/maps/documentation/javascript/reference#DirectionsRenderer, you can pass a DirectionsRendererOptions
api-doc https://developers.google.com/maps/documentation/javascript/reference#DirectionsRendererOptions 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.
您可以使用preserveViewport
的财产DirectionsRendererOptions
对象来控制渲染器如何与地图交互。环境preserveViewport
to true
将使地图显示保持不变:
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setOptions({ preserveViewport: true });
directionsDisplay.setDirections(response);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)