Ich bin derzeit in der Startphase ein App Wetter über Ionic Gebäude. Im Moment möchte ich die Cordova Geolocation implementieren, ich habe Fehler Unknown provider: $cordovaGeolocationProvider <- $cordovaGeolocation
Ich versuche zu beheben, aber erfolglos, aber dies hält einen Fehler beim Öffnen es. Zu Testzwecken verwende ich ionic serve und überprüfe es in localhost.
meinen Code
(function() {
angular.module('app.weather', ['ionic'])
.factory('Weather', function($q, $http) {
var deferred = $q.defer();
function getCurrentWeather(lat, lng) {
var url = 'https://api.forecast.io/forecast//' + lat + ',' + lng + '?callback=JSON_CALLBACK';
$http.jsonp(url)
.success(deferred.resolve)
.error(deferred.reject);
return deferred.promise;
}
return {
getCurrentWeather: getCurrentWeather
};
})
.controller('WeatherCtrl', function($scope, $cordovaGeolocation, Weather) {
$scope.loading = true;
$scope.toCelsius = function(temperature) {
return ((temperature - 32)/1.8).toFixed(1);
};
$cordovaGeolocation
.getCurrentPosition({
timeout: 10000,
enableHighAccuracy: false
})
.then(function(position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
Weather.getCurrentWeather(lat, long).then(function(data) {
$scope.weatherInfo = data;
$scope.loading = false;
}, function(error) {
//TODO Display error message
});
}, function(err) {
//TODO Display error message
});
});
})();
Code html
<ion-view title="الرئيسية" id="page2" style="background-color:#FFFFFF;" class=" ">
<ion-content padding="true" class="has-header">
<ion-pane>
<div ng-controller="WeatherCtrl as weatherCtrl">
<div ng-show="loading">
Carregando informações...
</div>
<div ng-hide="loading">
<p>
Temperatura: {{toCelsius(weatherInfo.currently.temperature)}}º
</p>
<p>
Sensação térmica: {{toCelsius(weatherInfo.currently.apparentTemperature)}}º
</p>
</div>
</div>
</ion-content>
</ion-view>
Versuchen Sie dieses Add http://stackoverflow.com/a/36158618/ 5059916 –
hast du 'ng-cordova'-datei enthalten? –