Note that there are some explanatory texts on larger screens.

plurals
  1. POGeolocation not working on webview android
    primarykey
    data
    text
    <p>I 'm trying to create an application where it will find the location of a user and it will show his location on a map. I have read the other articles about this issue and the suggested solutions but nothing worked for me. This Web app runs good in browsers (mobile and pc) but when I am trying to run it as an application stacks in the javascript of html file. I think that is a problem of permissions in javascript. This is the code of this project.</p> <p><strong>JAVA Code</strong></p> <pre><code>import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.GeolocationPermissions; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); WebView webview = (WebView) findViewById(R.id.webview); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); 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); } }); webview.loadUrl("file:///android_asset/www/geoMap.html"); } } </code></pre> <p><strong>AndroidManifest.xml</strong></p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="gr.######.navigator" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_GPS" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name=".MainActivity" android:label="@string/title_activity_main" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p><strong>HTML</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src="http://code.jquery.com/jquery-1.9.0rc1.js"&gt;&lt;/script&gt; &lt;script&gt; jQuery(window).ready(function(){ $("#btnInit").click(function() { alert('click button'); initiate_geolocation(); }); }); function initiate_geolocation() { alert('function initiate_geolocation'); navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors); } function handle_errors(error) { alert('function handle_errors'); switch(error.code) { case error.PERMISSION_DENIED: alert("user did not share geolocation data"); break; case error.POSITION_UNAVAILABLE: alert("could not detect current position"); break; case error.TIMEOUT: alert("retrieving position timed out"); break; default: alert("unknown error"); break; } } function handle_geolocation_query(position){ alert('function handle_geolocation_query'); alert('Lat: ' + position.coords.latitude + ' Lon: ' + position.coords.longitude); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;button id="btnInit" &gt;Find my location&lt;/button&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I 've spend several hours of searching and trying suggestion from the web but nothing worked. If someone knows something more about this issue please help.</p> <p>Thanks a lot.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload