I am writing an iOS app where the app must determine the current latitude longitude each time a page loads. I need to access the longitude and latitude from the event handler and pass the latest coordinates to a third party server.
I have been able to retrieve the coordinates using Cordova's navigator.geolocation.getCurrentPosition but need help to:
- Capture the coordinates each time a page loads
- Append the coordinate values to a GET request on an external URL.
so the question is simply can someone please advise me the correct syntax to be able to capture the value generated in the getlocation script below so i can have the co ords appended to the url so coords= the long / lat values generated
Here's my pageshow event handler code:
$("#HomePage").live("pageshow",
function() {
$.mobile.showPageLoadingMsg();
$.get("http://[externalurl]/process.cfc?method=HomePage&CORDS=[LATEST COORDS VALUE]]&returnformat=json", {}, function(res) {
$.mobile.hidePageLoadingMsg();
var s = "";
for(var i=0; i<res.length; i++) {
s+= "<li><a href='employeedetails.html?Id=" + res[i].Id + "'>Employee Details</a></li>";
s+= "<li><a href='OrgDetails.html?OrgId=" + res[i].OrgId + "'>OrgDetails</a></li>";
}
$("#HomePageContent").html(s);
$("#HomePageContent").listview("refresh");
},"json");
});
Below is the code I'm using to retrieve the users current coordinates. I just need to figure out how I can get the values into the jQuery function above so they can be appended to the GET request.
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = + position.coords.latitude +
"," + position.coords.longitude;
}