I played with the {X} api and I'm trying to get some location data, but as far as I try, I canβt figure out how to get / current / location.
Documentation:
This is their example:
// create GPS listener with update interval of 5 sec // you also use CELL or PASSIVE providers here var listener = device.location.createListener('GPS', 5000); // register on location changed listener.on('changed', function(signal) { // on receiving location print it and stop the provider console.info('Lat: ' + signal.location.latitude); console.info('Lon:' + signal.location.longitude); listener.stop(); }); // start the GPS listener listener.start();
However, it seems that this only works when changing location. How to get current location data (I'm sure there should be a way).
My current code is:
var lat; var lon; listener.on('changed', function (signal) { var lat = signal.location.latitude; var lon = signal.location.longtitude; listener.stop(); }); listener.start();
however, both lat and lon are both "undefined" when I check their contents. (because the device is not moved.)
source share