If you want to track the location using phonegap App, you can simply checkout this steps.
1. After creating a project for example "test", you can add a plugin using terminal
cordova plugin add org.apache.cordova.geolocation
After installing the plugin make sure your plugin is installed by using:
cordova plugin ls
It will show you something like this:
[ 'org.apache.cordova.geolocation' ]
After the confirmation of adding plugin, open your www folder and add the following lines in your code:
HTML :
<body>
<div id="findLocation"></div>
</body>
JS :
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
// On device feady it will call this function
}
function onSuccess(position) {
var div = document.getElementById('findLocation');
div.innerHTML = 'Latitude: ' + position.coords.latitude + '<br/>' +
'Longitude: ' + position.coords.longitude + '<br/>' +
'Altitude: ' + position.coords.altitude + '<br/>'';
}
function onError() {
alert('onError!');
}
</script>
It will give the Lattitude and Longitude of your location on device ready.
You can also get your location on click of some button or on any event.
0 Comment(s)