Here is the service code I have. The idea is to get a location update at X intervals.
In fact at app launch, I get two alert windows: one with proper app name and the second right after with ‘www/index.html’.
'use strict';
angular.module('ntf.services')
.factory('GeoLocation', function ($interval, Constants) {
var coords = null;
var promise = null;
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
coords = pos.coords;
if (!promise){
promise = $interval(function(){
navigator.geolocation.getCurrentPosition(success, error, options);
}, Constants.geolocationRefresh);
}
};
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
if (promise) $interval.cancel(promise);
coords = null;
};
navigator.geolocation.getCurrentPosition(success, error, options);
return {
coordinates: function(){
return coords;
}
};
});
var watchGeoLocation = $cordovaGeolocation.watchPosition({
timeout : 5*1000,
maximumAge:10000,
enableHighAccuracy: true // may cause errors if true
});
document.addEventListener("deviceready", function () {
watchGeoLocation.then(
null,
function(err) {
console.log("Error watch geo location:");
console.log(err);
},
function(position) {
var lat = position.coords.latitude
var long = position.coords.longitude
});
}, false);
my cordova version is 5.1.1 and my plugin is org.apache.cordova.geolocation@0.3.12
Have you ever try to put the $cordovaGeolocation.watchPosition() function into $ionicPlatform.ready()?