0
我在我的模板之一有一個僞指令中的GoogleMaps V3 domListener功能,以下是該指令的代碼:的PhoneGap沒有發射Angularjs指令
appDirectives.directive('map', function() {
return {
restrict: 'E',
scope: {
onCreate: '&'
},
link: function ($scope, $element, $attr) {
alert("This fires just fine.");
function initialize() {
alert("This doesnt fire on Phonegap.");
navigator.geolocation.getCurrentPosition(function (pos) {
$scope.currentLocation = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
var mapOptions = {
center: $scope.currentLocation,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true
};
var map = new google.maps.Map($element[0], mapOptions);
var currentLocation = $scope.currentLocation;
$scope.onCreate({
map: map,
currentLocation: currentLocation
});
// Stop the side bar from dragging when mousedown/tapdown on the map
google.maps.event.addDomListener($element[0], 'mousedown', function (e) {
e.preventDefault();
return false;
});
}, function (error) {
alert('Erro ao obter localização.');
});
}
google.maps.event.addDomListener(window, 'load', initialize());
}
}
當運行在瀏覽器上的應用程序,一切按預期工作。但是,在iOS模擬器上運行時,它並不會觸發函數initialize()。
我已經試過這(如描述here):
google.maps.event.addDomListener(window, 'load', initialize);
卜那麼它只是失敗,無論是在瀏覽器和simualtor工作。
任何想法爲什麼?
這是最好包括修復的相關部分在stackoverflow答案,這種方式答案保留在鏈接腐爛的情況下。 – mdewitt
@mdewitt它我的壞。希望現在好了 – Burhan