1
I’m not being able to show my location in the view, but using the.log(long) console I can see my location from the console. Where can I be missing? ` .controller('Geoctrl', Function ($Scope, $cordovaGeolocation) {
var posOptions = {
timeout: 10000,
enableHighAccuracy: true
};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
var lat = position.coords.latitude
var long = position.coords.longitude
console.log(long);
$scope.latitude = lat;
$scope.longitude = long;
}, function (err) {
// error
});
var watchOptions = {
timeout: 3000,
enableHighAccuracy: false // may cause errors if true
};
var watch = $cordovaGeolocation.watchPosition(watchOptions);
watch.then(
null,
function (err) {
// error
},
function (position) {
var lat = position.coords.latitude
var long = position.coords.longitude
$scope.latitude = lat;
$scope.longitude = long;
});
watch.clearWatch();
// OR
$cordovaGeolocation.clearWatch(watch)
.then(function (result) {
// success
}, function (error) {
// error
});
});
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Geolocalização</h1>
</ion-header-bar>
<ion-content ng-controller="GeoCtrl">
{{latitude}},{{longitude}}
</ion-content>
</ion-pane>
Try putting a
$scope.$apply();
within your function that brings the position, below the$scope.longitude = long
– joao paulo santos almeida
@joaopaulosantosalmeida is giving an error so Ionic.bundle.js:26794 Typeerror: Cannot read Property 'then' of Undefined, already went through it?
– rodrigo.oliveira