[英]angular-google-maps TypeError: $scope.map.control.refresh is not a function
I integrate angular-google-maps in my cordova mobile application. 我在我的cordova移动应用程序中集成了angular-google-maps。 I want to refresh map using the following function.
我想使用以下功能刷新地图。
function refreshMap() {
$scope.map.control.refresh({
latitude: $scope.location.T_Lat_Deg_W.value,
longitude: $scope.location.T_Long_Deg_W.value
})
}
But error apprears 但是错误很少见
angular.js:13540 TypeError: $scope.map.control.refresh is not a function
angular.js:13540 TypeError:$ scope.map.control.refresh不是函数
at Scope.refreshMap (mapController.js:122)
at fn (eval at <anonymous> (angular.js:1), <anonymous>:4:224)
at expensiveCheckFn (angular.js:15475)
at callback (angular.js:25008)
at Scope.$eval (angular.js:17219)
at Scope.$apply (angular.js:17319)
at HTMLAnchorElement.<anonymous> (angular.js:25013)
at defaultHandlerWrapper (angular.js:3456)
at HTMLAnchorElement.eventHandler (angular.js:3444)
Here is the JSFiddle example for this problem. 这是这个问题的JSFiddle示例 。
Is there a way to solve this problem ? 有没有办法解决这个问题? Thanks !
谢谢 !
Actually the key of this problem is that $scope.map.control.refresh
should not be used before the map is completely loaded. 实际上这个问题的关键是在完全加载地图之前不应该使用
$scope.map.control.refresh
。 If the map is initially hide, then I call a function like this 如果地图最初是隐藏的,那么我调用这样的函数
function refreshMap() {
//show map action
$scope.map.showMap = true;
//refresh map action
$scope.map.control.refresh({latitude: 48,longitude: 2.3});
}
The refreshMap
function will call the show map action and refresh map action at the same time. refreshMap
函数将同时调用show map动作并刷新map动作。 It means that map is not fully loaded when I call the $scope.map.control.refresh function. 这意味着当我调用$ scope.map.control.refresh函数时,map没有完全加载。 Thus, it will report the
TypeError: $scope.map.control.refresh is not a function
. 因此,它将报告
TypeError: $scope.map.control.refresh is not a function
。
One method is to use uiGmapIsReady
to detect whether the map is ready for usage. 一种方法是使用
uiGmapIsReady
来检测地图是否可以使用。
function refreshMap() {
//show map action
$scope.map.showMap = true;
//refresh map action
uiGmapIsReady.promise()
.then(function (map_instances) {
$scope.map.control.refresh({latitude: 48,longitude: 2.3});
});
}
This JSFiddle use uiGmapIsReady
to solve this problem. 这个JSFiddle使用
uiGmapIsReady
来解决这个问题。
The second method is to use $timeout
to delay the refresh action. 第二种方法是使用
$timeout
来延迟刷新操作。
function refreshMap() {
//show map action
$scope.map.showMap = true;
//delayed refresh map action
$timeout(function(){
$scope.map.control.refresh({latitude: 48,longitude: 2.3});
},3000);
}
This JSFiddle uses $timeout
to solve this problem. 这个JSFiddle使用
$timeout
来解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.