I am using angular.js with phonegap. To get users gps location I developed a simple service:
app.factory('geolocation', function ($rootScope, cordovaReady) {
return {
getCurrentPosition: cordovaReady(function (onSuccess, onError, options) {
navigator.geolocation.getCurrentPosition(function () {
var that = this,
args = arguments;
if (onSuccess) {
$rootScope.$apply(function () {
onSuccess.apply(that, args);
});
}
}, function () {
var that = this,
args = arguments;
if (onError) {
$rootScope.$apply(function () {
onError.apply(that, args);
});
}
}, options);
});
}
});
I call this service like this
geolocation.getCurrentPosition(function (position) {
console.log(position);
});
Now I want to extend the service with another method called getCurrentCity. This method should use getCurrentPosition to determine the city. So the service would look like this:
app.factory('geolocation', function ($rootScope, cordovaReady) {
return {
getCurrentPosition: ....
getCurrentCity: ...
}
});
Is this possible? How should I implement getCurrentCity by using getCurrentPosition?