angular google maps TypeError:$scope.map.control.refresh不是函数
angular-google-maps TypeError: $scope.map.control.refresh is not a function
我在我的cordova移动应用程序中集成了角度谷歌地图。我想使用以下功能刷新地图。
function refreshMap() {
$scope.map.control.refresh({
latitude: $scope.location.T_Lat_Deg_W.value,
longitude: $scope.location.T_Long_Deg_W.value
})
}
但错误适用于
angular.js:13540类型错误:$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)
下面是这个问题的JSFiddle示例。
有办法解决这个问题吗?谢谢
实际上,这个问题的关键是在映射完全加载之前不应该使用$scope.map.control.refresh
。如果地图最初是隐藏的,那么我调用一个类似的函数
function refreshMap() {
//show map action
$scope.map.showMap = true;
//refresh map action
$scope.map.control.refresh({latitude: 48,longitude: 2.3});
}
refreshMap
函数将同时调用显示地图操作和刷新地图操作。这意味着当我调用$scope.map.control.refresh函数时,映射没有完全加载。因此,它将报告TypeError: $scope.map.control.refresh is not a function
。
一种方法是使用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});
});
}
这个JSFiddle使用uiGmapIsReady
来解决这个问题。
第二种方法是使用$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);
}
这个JSFiddle使用$timeout
来解决这个问题。
相关文章:
- 如何解决Access Control Allow Origin错误
- 由于响应中不存在“Access Control Allow Origin”标头,跨域请求停止工作
- sessonStorage refresh splashscreen
- 调用Activex Control's javascript中的函数
- 编辑输出字符串函数ol.control.MouseControl
- Refresh iframe?
- XMLHttpRequest : 不被 access-control-allow-origin 所允许
- tinyMCE不会添加特定文本区域的Control
- jQuery Refresh Captcha正在重新加载页面
- AJAX/page refresh kills JS/jQuery
- 可以在Access Control Allow Origin中指定端口
- angular google maps TypeError:$scope.map.control.refresh不是函数
- 使用jQuery重复Control
- Access Control Allow Origin阻止我访问google api,尽管使用了dataType:
- JSONP跨原点错误'不存在Access Control Allow Origin标头'
- 角度:原点http://localhost在Access Control Allow Origin标头中找不到
- Angular$resource调用不被Access Control Allow使用Safari接受,而被Chrome接
- 在传单中创建自定义control.layers类
- Instagram API access_token request and Access-Control-Allow-
- 轨迹球控件js的tween control.reset()不工作