gpt4 book ai didi

javascript - NgMap,如何访问 Controller 中的方向? map.directionsRenderers[0].directions 在 Controller 中未定义。

转载 作者:行者123 更新时间:2023-11-28 04:55:59 25 4
gpt4 key购买 nike

我正在使用 NgMap,我需要在 Controller 中获取方向。我尝试过以下方法:

NgMap.getMap().then(function(map) {
console.log(map.directionsRenderers[0].directions);
});

但它返回未定义。我也尝试使用 $scope.map 但这也是未定义的。在我看来 {{map.directionsRenderers[0].directions.routes[0].legs[0].distance.text}} 按预期工作。

我的 map 如下:

<ng-map zoom="10" center="58.637381759037865,-3.0689620971679683">
<directions
draggable="false"
panel="directions-panel"
travel-mode="WALKING"
origin="58.637381759037865,-3.0689620971679683"
destination="50.063062230661494,-5.714178085327148"></directions>
<custom-marker id="start"
position="58.637381759037865,-3.0689620971679683">
<div> Start Here </div>
</custom-marker>
<custom-marker id="end"
position="50.063062230661494,-5.714178085327148">
<div> Ends Here </div>
</custom-marker>
</ng-map>

我错过了什么简单的事情?谢谢。

最佳答案

您可以使用以下名为 getDirections 的方法,如下所示:

ngMap.getMap()
.then(function (map) {
var renderer = map.directionsRenderers[0];
var directions = renderer.getDirections();
}

关于javascript - NgMap,如何访问 Controller 中的方向? map.directionsRenderers[0].directions 在 Controller 中未定义。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42552060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com