【发布时间】:2013-07-16 17:01:14
【问题描述】:
我正在使用带有 phonegap 的 angular.js。为了获取用户 gps 位置,我开发了一个简单的服务:
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);
});
}
});
我这样称呼这个服务
geolocation.getCurrentPosition(function (position) {
console.log(position);
});
现在我想使用另一个名为 getCurrentCity 的方法来扩展服务。此方法应使用 getCurrentPosition 来确定城市。所以服务看起来像这样:
app.factory('geolocation', function ($rootScope, cordovaReady) {
return {
getCurrentPosition: ....
getCurrentCity: ...
}
});
这可能吗?如何使用 getCurrentPosition 实现 getCurrentCity?
【问题讨论】:
标签: javascript angularjs cordova