I'm trying to do this a few hours and not succeeding.
I have a promise of $cordovaGeolocation returning latitude and longitude very basic equal to the ngCordova documentation.
I want to know how do I return the latitude and longitude in an array I have outside the function.
How can I do this???
Following the code structure.
$cordovaGeolocation.getCurrentPosition().then(function(position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
alert(lat + " | " + long);
}, function (err) {
console.log("fail");
});
var deviceInfo = {
uuid: uuid,
dataDevice: [
{
model: model
}
]
};
Thank you
function getCurrentPosition() {
var posOptions = {
timeout: 10000,
enableHighAccuracy: false
};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var coordinates = [lat, lng];
window.console.log("Coodenada:" + " " + coordenada);
return coordinates;
}, function(err) {
// error
console.log(err);
});
};