Cordova Geolocation load after all the element
Clash Royale CLAN TAG#URR8PPP
Cordova Geolocation load after all the element
I am facing issue with cordova geolocation. It is taking time to return the value. I used the timeout but it is not working as expected. I can't put too much time to the user to wait on.
Here is the code.
navigator.geolocation.getCurrentPosition(function(position)
$scope.userlongitude = position.coords.longitude;
$scope.userlatitude = position.coords.latitude;
console.log($scope.userlatitude);
console.log($scope.userlongitude);
);
Here is the Ajax code where I am using geolocation.
$timeout(function()
$http(
url: 'suggestions.php',
method: "GET",
params:
latitude: $scope.userlatitude,
longitude: $scope.userlongitude
)
.success(function(data)
$scope.news_suggestions = data.content;
);
, 3000);
Above code where i used http request fire before the geolocations return.
How to fix the issues.
Edit:
I tried device ready event but issue not resolved.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
-------- Codes are here. ----------
});
I tried device ready event but issue still there. Ajax fired before the geolocation send the data.
– Ironic
Aug 11 at 14:53
1 Answer
1
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition
Please use the default callback function
navigator.geolocation.getCurrentPosition(success, error, options);
var options = ;
function success(position)
$scope.userlongitude = position.coords.longitude;
$scope.userlatitude = position.coords.latitude;
$http(
url: 'suggestions.php',
method: "GET",
params:
latitude: $scope.userlatitude,
longitude: $scope.userlongitude
)
.success(function(data)
$scope.news_suggestions = data.content;
);
function error(err)
console.warn(`ERROR($err.code): $err.message`);
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You can call this on device ready event
– PPB
Aug 11 at 12:40