What is preventing the geolocation plugin from functioning properly in PhoneGap?

For too long, I've been struggling to make the geolocation feature work.

The errors on my console are as follows:

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."

At the top of my HTML file:

 <!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>

The contents of my location.js file are:

    // 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');
}

In addition, I have the necessary java classes in src/android and

   <gap:plugin name="org.apache.cordova.geolocation" />
included in my config.xml.

Answer №1

After encountering a problem, I made the decision to switch from the phonegap web interface to using cordova command line. This change enabled me to easily install the plugin and it is now functioning as intended.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue encountered while compiling Android code for the native interface

I have successfully integrated native Android PayPal code into my Codename One application using the native interface. To call the native code from CodenameOne: MyNative my = (MyNative)NativeLookup.create(MyNative.class); This is the structure of the Nat ...

What is the process for moving the final character to the beginning of a string?

Initially, the last letter in the string is being displayed. How can I rearrange it so that the last character appears first in the value? https://i.stack.imgur.com/uGq6H.jpg contentHtml += "<td rowspan1=\"" + 1 + "\" class=\"" + ( ...

When downloading an app from the Google PlayStore, error 504 or error 108 may appear. What are the possible reasons for these errors in the code?

Encountering error code -504 or -108 when trying to download an app from the Play Store can be frustrating. After spending a year developing an app, signing it, and uploading it as Beta, everything seemed to be going smoothly. Despite thorough debugging an ...

React is unable to recognize the 'delete key' in my KeyDown event detection

I've been struggling for days to capture a 'delete' key press event in React. No matter what I try, my function always seems to return false. What could be the reason for this? <textarea className="DetailsPage-t ...

I'm experiencing some challenges with setting up my sequelize relationships

After tirelessly searching for a solution to my problem and coming up empty-handed, I decided to reach out here. Every Google search result seems unhelpful and every link I click on is disappointingly pink. Hello everyone! I'm facing difficulties est ...

The Date() object is displaying incorrect information with inconsistencies in the month, day, and year

As of today, which is 3/15/11, I have created a new date object using the following code: Date now = new Date(); The output that I'm receiving is: the month showing as 2 (getMonth()), the day displaying as 2 (getDay()), and the year appearing as 1 ...

Determining the Nearest Date in an Array Using JavaScript

In my array, I store information about each day as an object. For example: {day_year: "2012", day_month: "08", day_number: "03", day_name: "mon"} To enhance the day objects, I have included a timestamp attribute using the following function: function co ...

Update the contents of a webpage using AJAX

Can anyone help me with loading likes into a div using AJAX every second? I want the page's URL to be likes.php?p=0 on page load, likes.php?p=1 after 1 second, likes.php?p=2 after 2 seconds, and so on. This is my code snippet: var loadLikes = func ...

Using React to showcase a base64 image representation

I'm struggling to show an image that has been sent from my Node/Express server to my React application. I've tried looking at solutions on other platforms, but so far nothing has worked for me. Let me outline the steps I have taken: The image is ...

Can you tell me the meaning of this error message: "The variable 'ParsedQs' cannot be assigned to a variable of type 'string'."

Hey there, I'm facing an issue with using the search query of mongoose. I want to make a get request using a query, but it seems that it's not possible. I'm puzzled by this error as I'm currently working with version 5.10.0 of mongoose. ...

JavaScript method being called twice during the second execution

Current Project Setup: I am currently utilizing jQuery, Bootstrap, and Font Awesome in this particular webpage. The setup involves creating a text box for user input. Upon finishing their input and hitting the 'enter' key, the item is then added ...

When the onclick event is triggered, it leads to the execution

Currently, I am developing a demonstration movie application where I have implemented onclick events using a function to retrieve movie-related data. However, I am encountering an issue when clicking on the specific links I need to work with, as it returns ...

What is the best method to deactivate additional choices and add inputs to several dropdown menus containing identical values using angular js?

Would like to have 3 dropdown lists with identical values. The first dropdown must be selected, while the other two are optional. All three dropdowns will have the same options. If a user selects an option in dropdown 1, it will become disabled for the re ...

The second angular $http call fails to reach its intended destination

I am in the process of setting up a flow similar to oauth, where I delay sending an actual request until some initial negotiation has been completed. The initial negotiation is successful, however, when I attempt to make the request for the desired resour ...

Avoid deleting a row in Sequelize if it is referenced in another association

Is there a method in Sequelize.js to trigger an exception when attempting to delete a row that is associated with another entity? For example, consider tables for Roles and Users. They have a many-to-many association, allowing any user to have multiple ro ...

Fetching content-type in React code locally executed

I am a beginner in front end development and I need help with setting the "application/json" content-type and gzip content-encoding in the fetch call for my locally run React code. Can anyone provide guidance on this? const data = await fetch(url, { ...

Limit the user to entering a maximum of (40) characters in the textarea

To enforce a character limit of 40 characters in a text area, I have implemented the following JavaScript function to trigger on the textarea's onKeyUp event: However, a problem arises when pasting content exceeding 40 characters into the textarea - ...

Prevent the clustering of advertisements using jQuery

Check out my code in action here! jQuery(document).ready(function(){ var insertionTemplate = jQuery(".hiddenAdBox").eq(0).html(), insertionTarget = jQuery('ul'), insertionTargetChildren = insertionTarget.find('li'), ...

Interfacing an Android application with an online database using Java

I currently have a database hosted on 1and1.com for my website.. Is there a way to connect the database from an Android device in order to store and retrieve information through the app? ...

Can PHP be incorporated with vBulletin seamlessly?

I am looking to seamlessly integrate vBulletin into a PHP page. I don't want to create a skin that simply matches the site's appearance, but rather have the forum fully integrated with the site. Of course, the skin would need to be modified to ma ...