javascript - GeoLocation in Android Webview -


i have android app uses web view. web view works well, except js uses getcurrentposition locate user. have read issue , understand need have right permissions, , have set setjavascriptenabled(true);. have done these things, still having lot of trouble android app. prompt requests permission obtain user's location doesn't come up. can me fix this? have included relevant java file, permissions manifest.xml, , js gets user's location. wonderful!


here java file:

package com.website.appname;  import android.app.activity; //other imports here  class myclient extends webchromeclient {      @override     public void ongeolocationpermissionsshowprompt(string origin,             callback callback) {         callback.invoke(origin, true, false);     } }  public class locationpage extends activity {     webview webview;     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.embed);         webview = (webview) findviewbyid(r.id.webview);         webview.setwebviewclient(new webviewclient());         webview.getsettings().setjavascriptenabled(true);         webview.setscrollbarstyle(view.scrollbars_inside_overlay);         webview.requestfocus(view.focus_down);         webview.setontouchlistener(new view.ontouchlistener() {             @override             public boolean ontouch(view v, motionevent event) {                 // todo auto-generated method stub                 return false;             }         });          webview.loadurl("http://www.website/page.php");         webview.setwebchromeclient(new myclient());         @suppresswarnings("unused")         class hellowebviewclient extends webviewclient {              @override              public boolean shouldoverrideurlloading(webview view, string url) {                  view.loadurl(url);                  return true;              }      } }     public boolean onkeydown(int keycode, keyevent event) {          if ((keycode == keyevent.keycode_back) && webview.cangoback()) {              webview.goback();              return true;          }          return super.onkeydown(keycode, event);  } } 

here permissions in manifest:

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

and here webpage loaded web view:

<script>        if( navigator.geolocation ) {            // call getcurrentposition success , failure callbacks            navigator.geolocation.getcurrentposition( success, fail );       }       else {            alert("sorry, browser not support geolocation services.");       }        function success(position) {           // geoposition object           window.location = "another_page.php?user_lat=" + position.coords.latitude            + "&user_lon=" + position.coords.longitude + "&accuracy=" +            position.coords.accuracy;       }       function fail() {            // not obtain location       }    </script>  <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 

p.s. have tried looking @ things android webview geolocation, helpful, issue still persists. thank you!

it looks geolocation timing out before position generated. try setting timeout period delay default timeout period.

navigator.geolocation.getcurrentposition(success,                                          fail,                                          {timeout:60000}); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -