2
votes

Been trying to get the geolocation to work for far too long now.

The console is giving me the following errors:

Coordinates.js:69 Uncaught ReferenceError: module is not defined(anonymous function) @ Coordinates.js:69

geolocation.js:24 Uncaught ReferenceError: require is not defined(anonymous function) @ geolocation.js:24

Position.js:22 Uncaught ReferenceError: require is not defined(anonymous function) @ Position.js:22

PositionError.js:38 Uncaught ReferenceError: module is not defined(anonymous function) @ PositionError.js:38

whitelist.js:23 No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin."

Head of my HTML:

 <!doctype html>
<html class="">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Study Time</title>

<link href="resources/css/boilerplate.css" rel="stylesheet" type="text/css">
<!--<link href="resources/css/index.css" rel="stylesheet" type="text/css">-->
<link href="vendors/jquery/slidemenu.hamburger.css" rel="stylesheet" type="text/css">
<link href="resources/css/index.css" rel="stylesheet" type="text/css">
<link href="resources/css/switch.css" rel="stylesheet" type="text/css">
<script src="cordova.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<!-- <script src="vendors/phonegap/micVolume.js"></script> -->
<script src="vendors/phonegap/location/Coordinates.js"></script>
<script src="vendors/phonegap/location/geolocation.js"></script>
<script src="vendors/phonegap/location/Position.js"></script>
<script src="vendors/phonegap/location/PositionError.js"></script>
<script src="resources/js/location.js"></script>

</head>

my location.js file is:

    // onSuccess Callback
// This method accepts a Position object, which contains the
// current GPS coordinates
//

function getLoc() {
  GPSLocation.getCurrentPosition(onSuccess, onError);
}

var onSuccess = function(position) {
    alert('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');
};

// onError Callback receives a PositionError object
//
function onError(error) {
    alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
}

And I do have the required java classes in src/android as well as <gap:plugin name="org.apache.cordova.geolocation" /> in my config.xml.

1

1 Answers

0
votes

I'm not sure why this wasn't working but since then I have decided to try moving away from the phonegap web interface and use cordova command line. This allowed me to install the plugin easily and it now works as expected.