Last active
March 22, 2017 07:12
-
-
Save mirkonasato/08789b5a724f5db9db72 to your computer and use it in GitHub Desktop.
Example of Angular service using ngCordova GeoLocation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var app = angular.module('app', ['ionic', 'ngCordova']); | |
app.factory('GeoService', function($ionicPlatform, $cordovaGeolocation) { | |
var positionOptions = {timeout: 10000, enableHighAccuracy: true}; | |
return { | |
getPosition: function() { | |
return $ionicPlatform.ready() | |
.then(function() { | |
return $cordovaGeolocation.getCurrentPosition(positionOptions); | |
}) | |
} | |
}; | |
}); | |
app.controller('LocationCtrl', function($scope, GeoService) { | |
function showMap(coords) { | |
var mapOptions = { | |
center: { lat: coords.latitude, lng: coords.longitude}, | |
zoom: 8 | |
}; | |
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); | |
} | |
GeoService.getPosition() | |
.then(function(position) { | |
$scope.coords = position.coords; | |
showMap(position.coords); | |
}, function(err) { | |
console.log('getCurrentPosition error: ' + angular.toJson(err)); | |
}); | |
}); | |
app.run(function($ionicPlatform) { | |
$ionicPlatform.ready(function() { | |
if (window.cordova && window.cordova.plugins.Keyboard) { | |
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); | |
} | |
if (window.StatusBar) { | |
StatusBar.styleDefault(); | |
} | |
}); | |
}); | |
}()); |
hi, am facing problem in the watcher,
the watcher is triggering even if the movement is not happened.
can u help me to fix this issue?
thanks in advance.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, I tested something similar but didn't work so I added a setTimeout with 10 milliseconds for delay and that worked.
I will try this again