Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Wait for Cordova to load
- document.addEventListener("deviceready", onDeviceReady, false);
- // Cordova is ready
- function onDeviceReady() {
- console.log("Entering index.html.onDeviceReady");
- var networkState = navigator.network.connection.type;
- getPosition(networkState);
- }
- function getPosition(networkState) {
- console.log("Entering getPosition function");
- console.log("networkState is: " + networkState);
- if (networkState !== null) {
- navigator.geolocation.getCurrentPosition(onSuccess, onError, {
- maximumAge : Infinity,
- timeout : 5000,
- enableHighAccuracy : true
- });
- } else {
- alert('Please check your network connection and try again.');
- }
- console.log("Leaving getPosition function");
- }
- // function for lat & lng
- function onSuccess(position) {
- console.log("Entering onSuccess(position) function");
- console.log("Latitude is: " + position.coords.latitude);
- console.log("longitude is: " + position.coords.longitude);
- lat = position.coords.latitude;
- lng = position.coords.longitude;
- console.log("Leaving onSuccess(position) function");
- }
- // function for lat & lng
- function onError(error) {
- console.log("Entering onError(error) function");
- alert('code: ' + error.code + 'n' + 'message: ' + error.message + 'n');
- console.log("Leaving onError(error) function");
- }
Add Comment
Please, Sign In to add comment