【发布时间】:2015-06-23 13:55:10
【问题描述】:
我有一个应用程序,它是一个欢迎/登录屏幕,在您签名后,您会进入一个包含四个标签的标签屏幕,其中第一个标签显示谷歌地图。
第一次登录页面时不会显示它自己,但在刷新页面时,地图会像预期的那样优雅地显示第一次。每次都会发生这种情况,但我只收到一个 javascript 错误。
错误
Uncaught Error: can't load XRegExp twice in the same frame(anonymous function) @ xregexp-min.js:2
代码
function initialize() {
var mapOptions = {
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(
document.getElementById("map"),
mapOptions
);
var geocoder = new google.maps.Geocoder();
$scope.map = map;
$scope.centerOnMe();
}
google.maps.event.addDomListener(window, 'load', initialize);
$scope.centerOnMe = function() {
if(!$scope.map) {
return;
}
$scope.loading = $ionicLoading.show({
content: 'Getting current location...',
showBackdrop: false
});
// get user location
$cordovaGeolocation
.getCurrentPosition({
timeout:10000,
enableHighAccuracy:true
})
.then(function(position) {
$ionicLoading.hide();
// we found the position
$scope.map.setCenter(
new google.maps.LatLng(
position.coords.latitude,
position.coords.longitude
)
);
}, function(e) {
$ionicLoading.hide();
console.log(e);
alert("Uh oh, we can't find your position! Is your GPS enabled?\n\n" + e);
});
};
编辑
这是我最新的 javascript 错误,在将 google init 替换为 ionic init 之后。我明白发生了什么,但我不知道应该将该函数声明移到哪里。我把它移到了 init 里面,但它仍然没有用。我应该设置超时吗?
TypeError: $scope.loadLocations is not a function
at initialize (controllers.js:179)
at Object.ionic.Platform.ready (ionic.bundle.js:2120)
at new <anonymous> (controllers.js:182)
at invoke (ionic.bundle.js:12468)
at Object.instantiate (ionic.bundle.js:12476)
at ionic.bundle.js:16745
at IonicModule.controller.self.appendViewElement (ionic.bundle.js:47716)
at Object.IonicModule.factory.ionicViewSwitcher.create.switcher.render (ionic.bundle.js:45973)
at Object.IonicModule.factory.ionicViewSwitcher.create.switcher.init (ionic.bundle.js:45893)
at IonicModule.controller.self.render (ionic.bundle.js:47590)
【问题讨论】:
标签: google-maps ionic-framework cordova-plugins ngcordova