我目前正处于通过 Ionic 构建应用程序的起始阶段。现在我想在其中实现 Cordova 地理定位。然而,打开它时总是出错。出于测试目的,我使用 ionic 服务并在本地主机中检查它。
angular.module('starter', ['ionic','ionic.service.core', 'ui.router'])
.controller('AgeCtrl', function ($scope, $state, $http, $cordovaGeolocation) {
$scope.toggleItem = function (item) {
item.checked = !item.checked;
};
$scope.items = [
{ id: '0-12' },
{ id: '12-18' },
{ id: '18-30' },
{ id: '30-65' },
{ id: '65+' }
];
$scope.time = Date.now();
$scope.weather = $http.get("http://api.openweathermap.org/data/2.5/weather?q=Amsterdam&units=metric&APPID=...").then(function(resp) {
console.log("success", resp);
}, function(err) {
console.log("error");
})
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
var lat = position.coords.latitude
var long = position.coords.longitude
console.log(lat + ' ' + long)
}, function(err) {
console.log(err)
});
$scope.Confirm = function (){
$state.go('home');
}
})
我是否有什么地方犯了错误导致了这个问题?
最佳答案
ionic 服务仅模拟浏览器中的应用程序。 您无法在浏览器中访问 Cordova 插件。
要获取包含的库,您需要在添加特定平台后在设备上运行应用程序,具体取决于您拥有的设备。
对于 iOS:
Ionic platform add ios
对于安卓:
ionic platform add android
添加平台后,您可以使用以下命令在设备上构建并运行
对于 iOS:
ionic run iOS
对于安卓:
ionic run android
关于javascript - ionic.bundle.js :25642 Error: [$injector:unpr] Unknown provider: $cordovaGeolocationProvider <- $cordovaGeolocation <- AgeCtrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36157833/