1

I am trying to fix an Android app that is a webview to a site that was uses the HTML5 Geocoding function. The site displays a GoogleMap and if the site is allowed to know the user's location then it will add a second marker at the user's location and display directions on the map.

As of right now inside the webview there is no button that pops down asking for permission to know the user's location and also no feedback indicating that it does know the user's location. I would be okay with either of these things happening.

The app asks for permission to internet, access_network_state and access_fine_location

I'm not sure if there is some other permission I have to grant it that I haven't been able to find or if there's a way to use the access_fine_permission to pass to the website.

OrangeGrover
  • 457
  • 2
  • 8
  • 21
  • You don't mention what if the app has a webview to native layer like: phonegap or something custom. – Morrison Chang May 13 '12 at 23:51
  • @MorrisonChang - The app doesn't use phonegap or anything like that. It's just like the basic tutorial here (plus a few other buttons): [HelloWebview](http://developer.android.com/resources/tutorials/views/hello-webview.html) – OrangeGrover May 14 '12 at 00:32

1 Answers1

2

There are a few things you need to do:

  • webview.getSettings().setJavaScriptEnabled(true);
  • webview.getSettings().setGeolocationEnabled(true);
  • Assign a WebChromeClient to the WebView and override onGeolocationPermissionsShowPrompt. You can either grant the permission silently, or implement a dialog to ask the user.

Here are the details: android webview geolocation

Community
  • 1
  • 1
chiuki
  • 14,580
  • 4
  • 40
  • 38