Cordova Geolocation

2

I'm having a very strange problem, I have an app running a year and after a few months with no updates when making a new release I realized that the geolocation was not working correctly. When I use the getCurrentPosition function there is no error, however the object returned is empty. I made a new app just to test and the same problem occurred. I'm testing with Ionic .

I need an urgent solution. Has there been any update on how to implement this recently?

Example:

Result:

  

As you can see from this basic example, I just wanted to see the   information returned, but for some reason that I do not know   but the object is empty.

    
asked by anonymous 20.05.2016 / 14:38

2 answers

2

It's not returning anything because you put it in

if(window.cordova && window.cordova.plugins.Keyboard)

Place outside of , its function:

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    navigator.geolocation.getCurrentPosition(function(res) {
      console.log("deu certo...");
      console.log(JSON.stringify(res.coords));
    }, function(err) {
      console.log("deu erro...");
      console.log(JSON.stringify(err));
    })

    if (window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

I hope I have helped you!

Hugs!

    
20.05.2016 / 20:08
0

Try this:

    var positionOptions = {maximumAge:0, timeout: 30000, enableHighAccuracy: true};

    function gpsSuccess(obj){
      console.log('GPS Success latitude: ' + obj.coords.latitude);
      console.log('GPS Success longitude: ' + obj.coords.longitude);
    }

    function gpsError(obj){
      console.log('Gps error' + JSON.stringify(obj));
    }

    navigator.geolocation.getCurrentPosition(gpsSuccess, gpsError, positionOptions);
    
20.05.2016 / 20:01