Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1.  
  2. function GeolocationSync(){
  3.  
  4. var existLatLong = Application.getPosition();
  5. if(existLatLong === null){
  6.  
  7. $ionicLoading.show({
  8. templateUrl: 'templates/components/sync.html',
  9. scope: $scope
  10. });
  11.  
  12. if(window.cordova !== undefined){
  13. if($cordovaDevice.getDevice().platform === "Android"){
  14. isGpsEnabled();
  15. var intervalPromisse = $interval(function(){
  16. isGpsEnabled();
  17. },4000);
  18. }
  19. else{
  20. getLocation();
  21. }
  22. }
  23. else{
  24. getLocation();
  25. }
  26.  
  27. }
  28.  
  29. function isGpsEnabled() {
  30. var gpsEnabled = window.plugins.locationAndSettings;
  31. gpsEnabled.isGpsEnabled(function(result) {
  32. if (result === false) {
  33. if($scope.openConfigLocation === false)
  34. switchToLocationSettings();
  35. }
  36. else{
  37. $interval.cancel(intervalPromisse);
  38. getLocation();
  39. }
  40. }, function() {
  41. alert("error");
  42. });
  43. }
  44.  
  45. function switchToLocationSettings() {
  46. var configLocation = window.plugins.locationAndSettings;
  47. configLocation.switchToLocationSettings(function(result) {
  48. if(result){
  49. $scope.openConfigLocation = true;
  50. }
  51. }, function() {
  52. alert("error");
  53. });
  54. }
  55.  
  56. function getLocation(){
  57.  
  58. var watchOptions = {
  59. frequency : 100000,
  60. enableHighAccuracy: true
  61. };
  62.  
  63. var watch = $cordovaGeolocation.watchPosition(watchOptions);
  64. watch.then(
  65. null,
  66. function(err) {
  67. console.log(err);
  68. },
  69. function(position) {
  70. var lat = position.coords.latitude;
  71. var lng = position.coords.longitude;
  72. Application.setPosition([lat, lng]);
  73. $ionicLoading.hide();
  74. });
  75.  
  76.  
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement