Reputation: 189
i am new to html5 and using cordova and has the code as below. once i use the html5 geo location object i need to display the value in the user current screen.The code is as below
function onDeviceReady() {
// Get the most accurate position updates available on the
// device.
var options = { enableHighAccuracy: true };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
}
// onSuccess Geolocation
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'<hr />' + element.innerHTML;
}
document.write=(element);
<body class="sapUiBody" role="application">
<p id="geolocation"need to display user geo location here </p>
</body>
Upvotes: 0
Views: 679
Reputation: 177
The HTML code:
<p id="geolocation">your coordinates:</p>
The JavaScript code:
var x = document.getElementById("geolocation");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
function showPosition(position) {
x.innerHTML+="<br>Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
Upvotes: 1