Geolocation doesn't working in emulator, but in web working fine, how to solve?


#1

.factory(‘position’, function( $rootScope, $cordovaGeolocation ){

    console.log('building position')
  
    var position = {};
      // 1ST / AUTO GEOLOCATION OF USER 
      // displays a popup to indicate current user location - (disabled)
      // onSuccess Callback - This method accepts a Position object, which contains the current GPS coordinates


     // Wait for device API libraries to load
//

     var onSuccess = function(position2) {
         
          console.log(position2.coords.latitude )
          console.log(position2.coords.longitude)
          
          position.latitude = position2.coords.latitude;
          position.longitude = position2.coords.longitude;

          
          
         $rootScope.$digest()
      };

    function onError(error) { // onError Callback receives a PositionError object
        console.log('error code:', + error.code +'\n')
    };

    //var options = { enableHighAccuracy: true, maximumAge: 15000, timeout: 10000 };
    var options = {maximumAge: 15000, timeout: 30000, enableHighAccuracy:false};

    //var watchID = navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
    navigator.geolocation.watchPosition(onSuccess, onError, options);



    
  return position;

})


#2

You need to read the log from ADB if you’re using Android emulator or iOS logs to see what’s happen when you request the geolocalisation. If you are on Android, are you sure that you configured your emulator with GPS set to ON?


#3

In my AndroidManifest.xml has GPS active, I’m using this "uses-feature android:name=“android.hardware.location.gps”


#4

@waraujo Ok but what I was saying it’s you need to make sure that if you are using an emulator, the GPS have to be set to ON before to generate the Android image. Also you may need to test this on a real device with GPS set to ON as well. Again, read your logs to know if you have any errors when you are trying to trigger the geolocalisation.


#5

@Devniz Now it’s working fine, just work on device. Thanks!