Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8186087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:04:28+00:00 2026-06-07T02:04:28+00:00

I am very new to android, java and javascript coding. I am trying to

  • 0

I am very new to android, java and javascript coding.

I am trying to get current GPS co-ordinates and track it thereafter on an Android device. I am using webview and the majority of the code is written in javascript.

I have searched a lot for a few days and tried many different ways but I am unable to get GPS co-ordinates on the android device. Please have a look at the code and hel pme figure out why I am not getting the GPS location.

A few things to point are –
1. I downloaded and checked other sensor apps and can see the current GPS co-ordinates being shown (so the GPS is working on the device).
2. When I run my code, I see the GPS searching icon in the notification area, it keeps blinking but never fixes.
3. When I run only the HTML file with the javascript on a laptop browser, it ask permission to share location and then it gives the co-ordinates, however the same file does not show anything in android.

Please have a look at the code below and help me figure this out. I have tried a lot and am posting this as my last hope.

The manifest file has the following permissions –

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />

The main java code in Android has –

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    webView = new WebView(this);  
    webView.getSettings().setJavaScriptEnabled(true);   
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.loadUrl("file:///android_asset/mymap.html");
    setContentView(webView);
}

And the HTML file with the javascript is –

<!DOCTYPE html>
<html>
<body onunload="OnUnload()" onload="getLocation()">
<p id="demo">Your coordinates:</p>
<script>
var watchID;
var x=document.getElementById("demo");
function getLocation()
  {
  if (navigator.geolocation)
    {
       var options = {maximumAge:600000, timeout:100000, enableHighAccuracy: true};
       watchID = navigator.geolocation.watchPosition(showPosition,showError,options);
    }
  else{x.innerHTML="Geolocation is not supported by this browser.";}
  }
function showPosition(position)
  {
  x.innerHTML="Latitude: " + position.coords.latitude + 
  "<br />Longitude: " + position.coords.longitude;  
  }
function showError(error)
  {
  switch(error.code) 
    {
    case error.PERMISSION_DENIED:
      x.innerHTML="User denied the request for Geolocation."
      break;
    case error.POSITION_UNAVAILABLE:
      x.innerHTML="Location information is unavailable."
      break;
    case error.TIMEOUT:
      x.innerHTML="The request to get user location timed out."
      break;
    case error.UNKNOWN_ERROR:
      x.innerHTML="An unknown error occurred."
      break;
    }
  }

function OnUnload()
{
   alert ("The current document will be unloaded!");
   navigator.geolocation.clearWatch(watchID);
}  
</script>
</body>
</html>

Thanks a lot in advance,
axs

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:04:29+00:00Added an answer on June 7, 2026 at 2:04 am

    Well I did further search and found a solution. I am posting these links here as answer to my question for anyone who comes till here looking for answers.

    I had to add these lines in my java code before loading the url and then I was able to see the geo-coordinates.

        webView.getSettings().setGeolocationEnabled(true);
        webView.setWebChromeClient(new WebChromeClient() {
             public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
                // callback.invoke(String origin, boolean allow, boolean remember);              
                callback.invoke(origin, true, false);
             }
            });
    

    For more information follow these two links –

    • android webview geolocation
    • Android: Using html5 to determine geolocation in webview with javascript api
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to java and trying to develop an Android app called
I am very new to Java and android. my 1st app using canvas and
I am very new to Android development, and I am trying to get a
I'm very very new to android & JAVA, and I'm trying to learn writing
I am very new to Android development and Java. Have read around but I'm
I'm still very new to Android, but I am trying to keep up by
I'm very new to java and am working on my first Android app. I
Just a disclaimer, I'm very new to both android and Java. The end product
I am very new to Android. I am trying to build inflate a context
I'm very new to android, in fact only started yesterday. I managed to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.