Sample code

HTML file (index.html):

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Cordova Background Geolocation Example App</title>
    </head>
    <body>
        <div id="root"></div>
        <!-- Include Cordova APIs -->
        <script src="cordova.js"></script>
    </body>
</html>

Cordova APIs via JS (cordova.js):

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    /* Call Cordova APIs - Plugin Geolocation */
    navigator.geolocation.getCurrentPosition(geolocationSuccess);
    console.log("navigator.geolocation works well");
}
var geolocationSuccess = function(position) {
    console.log('Latitude: '          + position.coords.latitude          + '\n' +
                'Longitude: '         + position.coords.longitude         + '\n' +
                'Altitude: '          + position.coords.altitude          + '\n' +
                'Accuracy: '          + position.coords.accuracy          + '\n' +
                'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
                'Heading: '           + position.coords.heading           + '\n' +
                'Speed: '             + position.coords.speed             + '\n' +
                'Timestamp: '         + position.timestamp                + '\n');

    console.log("navigator.geolocation works well");
};

results matching ""

    No results matching ""