Skip to main content
Participating Frequently
August 2, 2012
Question

Android - StageWebView with Geolocation

  • August 2, 2012
  • 3 replies
  • 4074 views

I'm creating a cross-platform app using Flash CS6 targeted at AIR 3.3.0.3650. I setup a StageWebView and load a URL which uses geolocation via Google's JS API.

I've ported my code from a working IOS implementation into Android. The code worked 100% fine on IOS, however, I do not get any prompts for permission to use a current location on the Android platform, and thus the map does not load or show your geolocation.

I've kept the appplication and code to a complete minimum, but I'm still banging my head against the wall to get a prompt or get the geolocation working. If you were to visit the URL below via a desktop browser or the Android's default browser, the geolocation works. When you load it via StageWebView, the map portion remains blank.

I have also set all permissions to allow for location services, etc. to no avail. Here is the barebones code that I'm running with to troubleshoot. I've even went as far as to use someone else's website in the StageWebView instance to make sure it wasn't an error within the loaded page.

var webView:StageWebView;

webView = new StageWebView();

webView.stage = stage;

webView.viewPort = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);

webView.loadURL("http://merged.ca/iphone/html5-geolocation/");

This topic has been closed for replies.

3 replies

Inspiring
July 4, 2019

Not sure if it works, but worth a try.

You can handle the permission from as3 and use the geoloc in the webview. Not sure it's the same permission tho.

Inspiring
August 19, 2015

Although the original post is related to 3 years ago, there has never been a solution to this problem until now! I am very happy to announce the release of V3.0 of RichWebView which we included support for GPS so in your JS codes, you can grab user latitude, longitude as follow. Read this tutorial to know how to manage this in your Adobe Air mobile app.

var gpsOptions = {

  enableHighAccuracy: false,

  timeout: 5000,

  maximumAge: 0

};

function onGpsSuccess(pos) {

  var crd = pos.coords;

  alert('Your current position is:\nLatitude : ' +

  crd.latitude + '\nLongitude: ' +

  crd.longitude + '\naccuracy: ' +

  crd.accuracy + 'meters');

};

function onGpsError(err) {

  alert('ERROR(' + err.code + '): \n' + err.message);

};

function getUserLocation()

{

    navigator.geolocation.getCurrentPosition(onGpsSuccess, onGpsError, gpsOptions);

}

Inspiring
July 3, 2019

emstris

emstris

I need to have a working google maps with gps in a webview.

cheers

jdkuzmaAuthor
Participating Frequently
August 6, 2012

I've gotten a bit closer to the answer, as it seems the native coding for Android has to use a work around to show the prompt as well:

http://stackoverflow.com/questions/5329662/android-webview-geolocation

Is there anyway to implement "setWebChromeClient" via AIR?

jdkuzmaAuthor
Participating Frequently
August 14, 2012

This is how it would be done if i were coding directly for Android:

WebSettings webSettings = myWebView.getSettings();
webSettings
.setJavaScriptEnabled(true);

Does anyone know of a way to do the same using StageWebView with AIR for Android?

ProducerTina
Participant
February 25, 2013

I'm having this issue as well. Has anyone discovered a work-around yet?