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 6239533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:24:33+00:00 2026-05-24T11:24:33+00:00

I’ve looked at the various questions regarding this problem on here such as: Using

  • 0

I’ve looked at the various questions regarding this problem on here such as:

  • Using navigator.geolocation.getCurrentPosition in WebView on Android 2.0+ (PhoneGap related)
  • android webview geolocation
  • Android: Using html5 to determine geolocation in webview with javascript api

But I’m still a bit confused, I know that I am supposed to create my own class from the abstract class WebChromeClient. Which gets the location, but how exactly from there does this object send the webView the geolocation/how do they communicate?

Here is my code: (is this at least on the right track?)

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.GeolocationPermissions.Callback;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.GeolocationPermissions;

public class site extends Activity {
WebView engine;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    WebViewClient yourWebClient = new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.contains("tel:") == true) { 
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); 
                startActivity(intent); 
            }
            else if(url.contains("visitchicagosouthland") == true) {
                view.loadUrl(url);
            }

//Here is where I create my object, I did this because I only need the location when this
//page is loaded. Could this be part of the problem?

            else if(url.contains("directions.cfm") == true) {
                GeoClient geo = new GeoClient();
                engine.setWebChromeClient(geo);        
                String origin = ""; //how to get origin in correct format?
                Callback call = null;
                geo.onGeolocationPermissionsShowPrompt(origin, call );  
            }
            else {
                /*Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("url")); 
                startActivity(browserIntent);*/
            }
        return true;
        }
    };


    engine = (WebView) findViewById(R.id.web_engine);
    engine.getSettings().setJavaScriptEnabled(true);
    engine.getSettings().setBuiltInZoomControls(true);
    engine.getSettings().setSupportZoom(true); 
    engine.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    engine.getSettings().setGeolocationEnabled(true);
    engine.setWebViewClient(yourWebClient);
    engine.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    engine.loadUrl("http://www.visitchicagosouthland.com/jrudnydev/phone/");
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.home, menu);
    return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && engine.canGoBack()) {
        engine.goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    if(item.getItemId() == R.id.home) {
        engine.loadUrl("http://www.visitchicagosouthland.com/mobile/");
        return true;
    }
    else if(item.getItemId() == R.id.refresh) {
            engine.reload();
            return true;
    }
    else if(item.getItemId() == R.id.stop) {
            engine.stopLoading();
            return true;
    }
    else {
        return super.onOptionsItemSelected(item);
    }
}

}

final class GeoClient extends WebChromeClient {

  @Override
    public void onProgressChanged(WebView view, int progress) {
        // Activities and WebViews measure progress with different scales.
        // The progress meter will automatically disappear when we reach 100%
        //Activity.setProgress(progress * 100);
    }

@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
    //Log.d(LOG_TAG, message);
    // This shows the dialog box.  This can be commented out for dev
    AlertDialog.Builder alertBldr = new AlertDialog.Builder(null);
    alertBldr.setMessage(message);
    alertBldr.setTitle("Alert");
    alertBldr.show();
    result.confirm();
    return true;
}

@Override
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
// TODO Auto-generated method stub
super.onGeolocationPermissionsShowPrompt(origin, callback);
callback.invoke(origin, true, false);
}

}

my android-manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.visitchicagosouthland"
  android:versionCode="1"
  android:versionName="1.0">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<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" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".site"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>
<uses-sdk android:minSdkVersion="4" />

</manifest> 
  • 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-05-24T11:24:34+00:00Added an answer on May 24, 2026 at 11:24 am

    It is rather simple when the html is your own. There are a couple of ways, I will give you 2 of them.

    Simple way using GET

    Idea is to send the location in the URL (you might need some encoding but as long as it’s only numbers and no spaces you are fine

    Some editing for your shouldOverridUrlLoading

    public boolean shouldOverrideUrlLoading(WebView view, String url){
        if (url.needs_geo) //meaning if this is the url that needs the geo location
            url += "?geo=" + your_location;
        view.loadUrl(url);
        return true;
    }
    

    In your JavaScript:

    function getParam(name)
    {
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( window.location.href );
      if( results == null )
        return "";
      else
        return results[1];
    }
    

    then

    var geo_location = getParam('geo');
    

    Using WebView.addJavascriptInterface

    (I have never tried to pass values from Java to JavaScript but will probably work as well). The idea is to provide for your JavaScript a Java class that can be accessed to get the parameters you want to pass to JavaScript.

    Inside your Activity class:

    public String location; //as an example
    
        public class SherifJS {
            public String getLocation(){
                return location;
            }
        }
    //bla bla
    
        SherifJS loc = new SherifJS();
        yourWebView.addJavascriptInterface(loc, "locationProvider"); 
    

    Inside your JavaScript:

    <script type="text/javascript">
            <!--
    
    function sherifJS() {
        document.getElementById("locationHolder").innerHTML =
        window.locationProvider.getLocation();
    }
    
            -->
    </script> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've looked in various resources regarding this topic, and it seems to me that
I've looked through various other questions about this and they are all fixed by
I've looked through various questions both here and other places, but I still cannot
I've looked at the various questions that mention this specific exception ( this question
I've looked at various Q&As on SO similar to this question but haven't found
I've looked at the answers to various questions , but haven't managed to map
I have looked over a few similar questions here at stackoverflow and I can't
Yes, I looked at various ways of implementing GOTO in java, but here is
I've looked through the various questions on unit testing but can't find one that
I looked in the Rails docs under inflector and found this message... Module deprecated

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.