引用它
如使用ngmap的direction api的示例所示,使用map变量来获取路线的总长度。
{{map.directionsRenderers[0].directions.routes[0].overview_path.length}}
如在下面的示例中。
视图源:https://rawgit.com/allenhwkim/angularjs-google-maps/master/testapp/directions.html
但我想把这个变量放在我的控制器里,因为我想做我自己的方向盘
我尝试在控制器中使用$scope.map
,但它不起作用。
请帮忙。
在您的控制器中,您希望初始化映射对象,如下所示:
$scope.$on('mapInitialized', function(event, map) {
map.setOptions({
});
});
显然,您想在init上设置的任何选项都会在side map.setOptions.中声明
初始化后,您应该能够使用$scope.map