Using geolocation on emulator / Android 2.2

524 views
Skip to first unread message

Jen Smith

unread,
Aug 12, 2010, 5:51:59 AM8/12/10
to phonegap
Hello,

I am having some problems getting the phonegap geolocation code to
work on the version 2.2 emulator.

I understand from this article :
http://stackoverflow.com/questions/2267513/using-navigator-geolocation-getcurrentposition-in-webview-on-android-2-0-phoneg
and from reading through the code that phonegap delegates to the
native browser support for geolocation where it is available.

However, on the emulator I am using (both the 2.2 emulator and the
'Google APIs' emulator) does not seem to support native browser
geolocation. This was true both from my sample phonegap application
and from the browser. When calling
navigator.geolocation.getCurrentPosition , the error callback is fired
with a code of 2 and a message of "The last location provider was
disabled". 'Geo fix' does not help here either.

I patched my version of PG to include the patch linked in the
stackoverflow post above (even though it seems to have been changed in
the latest head on github). When I do this, I get the error :
ReferenceError: Can't find variable: Geo at file:///android_asset/tools/phonegap.js:804

I looked in the code and saw that the DroidGap activity does not
actually load Geo unless we are on API version 1

if (android.os.Build.VERSION.RELEASE.startsWith("1."))
{
cupcakeStorage = new Storage(appView);
geo = new GeoBroker(appView, this);
appView.addJavascriptInterface(cupcakeStorage, "droidStorage");
appView.addJavascriptInterface(geo, "Geo");
}

I went ahead and took the geo initialisation out of the if statement
and ran it through the emulator again. Now the getCurrentLocation call
does not return until I give it a geo fix, at which point it is
successful!

So I have a few questions now:

- Is there any reason that the GeoBroker initialization is disabled in
2.x ? (i.e. am I safe to reenable it ?)
- Is there any way to make getCurrentLocation fail a bit faster or
timeout (that way I suppose I can get the last known location)


Thanks and let me know if you need more information.

Jennifer Smith

Jen Smith

unread,
Aug 12, 2010, 5:54:48 PM8/12/10
to phonegap
Update:

I did manage to get something together that lets me use geolocation in
both the browser and the 2.2 emulator. In the emulator I use the
phonegap geolocation. Have not actually tried it on a real device
though! My fork is here:

http://github.com/jennifersmith/phonegap-android

Also had to make the GeoBroker.stop method actually stop the supplied
listener as I wanted to be able to turn on/off the listener from my
javascript code (so I can cancel lookup after a set timeout).

thanks

Jen



On Aug 12, 10:51 am, Jen Smith <jennifer.e.m.sm...@gmail.com> wrote:
> Hello,
>
> I am having some problems getting the phonegap geolocation code to
> work on the version 2.2 emulator.
>
> I understand from this article :http://stackoverflow.com/questions/2267513/using-navigator-geolocatio...

Alexandre Busquets

unread,
Aug 23, 2010, 6:36:23 AM8/23/10
to phonegap
Sorry,

can you use the geolocation?

I also have problems, always I have this error message: "The location
provider was disabled".
Reply all
Reply to author
Forward
0 new messages