Wednesday, March 03, 2010

Testing Geolocation for Mobile Web Apps

Using geolocation in a web application is really cool. The JavaScript API is quite simple. Testing it, can be a different story. Here are some useful tips:

If you only need to get the user's location once, testing is not too bad at all. First, you can actually use Firefox 3.5+. However, make sure that you are using wi-fi, or otherwise you will never get a location. Your app will just seem to hang. Anyways, being able to use Firefox for testing is great because it is a full desktop browser with awesome developers tools like Firebug. Often you will have some pretty complex JavaScript in a web application that uses geolocation, so being able to debug with Firefox/Firebug is invaluable.

Of course you will also want to test on mobile browsers. You can definitely use the iPhone simulator that is part of the iPhone SDK. Geolocation works great on this, but it gives you a bogus location -- the location of Apple's HQ in Cupertino, CA. If you actually live near Cupertino, this can be really misleading. Anyways, it will only give you this location, never anything else. So it is somewhat limited.

Testing on an Android emulator is another possibility. However, in my experience, it is currently broken. On an Android device, when a web page wants your location, the browser brings up a window to prompt you for permission. On the emulator's browser, I never see this permission window and the app just hangs and never returns a location. That's a bummer, since the Android SDK makes it possible to send mock GPS coordinates to an Android emulator. It would be great if web developers could take advantage of this.

Testing on an actual devices is of course a possibility. Your web application needs to be reachable by the device. This could mean using wi-fi on your device, so you are in the same intranet as your development sever, or it could mean deploying your app somewhere public. I like using the Google App Engine for the latter, and then test on the assortment of devices that I have laying around.

If you need to test location updates, i.e. when the user moves you want your web application to know about it and respond in some way, then things get trickier. The iPhone simulator is out of the question. An Android emulator still suffers from the same problems. So now you are down to devices. There is no way to send mock GPS to an iPhone, so to test on an iPhone, you need to actually change your physical location. Coding and driving FTW!

However, it should be possible to test on an Android device. The Android SDK theoretically allows you to send mock GPS to a real device. The command that should work is "adb -s XXX shell geo fix AAA BBB" where XXX is the serial number of your device (get it by doing "adb devices"), and AAA/BBB are the fake latitude/longitude. Sounds good, right? I tried this on my Nexus One, and got a big fat permission denied. Turns out you need to be root to do this on a real device. Ok, so I rooted my Nexus One. Then I tried it. Result? "gps: not found." Suddenly the gps command was not recognized. So ... coding and driving FTW!

13 comments:

matt m said...

I was just running into this same issue - turns out you have to telnet in order to issue the "geo" command, as it does not exist under /system/bin/ like the other 'commands' do (on the Android emulator at least).

So what I did was:
%>telnet localhost 5554
...
OK
geo fix -122.45677 44.55554


Or using netcat:
nc localhost 5554 <<<"geo fix -122.45677 44.55554"

However, it doesn't seem to do anything... at this point I think my code is the issue.

Does it work for you?

Michael Galpin said...

@matt -- Are you telneting into a device, or an emulator? Usually 5554 is the port of an emulator. If you are telneting into a device, how are you doing that?

Mac Blog said...

I have the same problem, did you get any solution Michael?

Anonymous said...

Thanks for your post. Gave me lots of tips for my first geolocated web app. Check it out. It's a simple group chat and coordination app. http://www.enlegion.com

Nick Christo said...

This can be made easier with a Mobile development platform. I work for GeoLoqal. We have a platform that lets developers build, test and monetize Location-aware applications. Developers can test exactly how the App would behave in the user's hands with this platform.Also, if you don't want to take the trouble of collating huge chunks of data, you can try a Mobile development platform that also has an integrated Places data. More user data also means relevant services to users. This opens up a huge market for developers to offer more value added services to users. I work for a company called GeoLoqal. The GeoLoqal Mobile development platform helps developers create, test and monetize Location-Aware Applications. You can also test how exactly the App would behave in the user's part in any part of the world. GeoLoqal’s back end data results in enhanced user engagement with NearU (events, news, geotagged data, deals etc) functionality.


There is a free sign up option to test drive the platform. Will be happy to schedule a demo!
http://www.geoloqal.com


Regards,
Nick
Techie @ http://www.geoloqal.com

Banu said...

Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving..
Mobile App Development Company
Android app Development Company
ios app development Company
Mobile App Development Companies

Anu said...

I’ve been browsing on-line greater than three hours today, but I never discovered any attention-grabbing article like yours. It is beautiful worth sufficient for me. Personally, if all webmasters and bloggers made good content material as you did, the net will be a lot more helpful than ever before.
iOS Training in Chennai
Android Training in Chennai
php Training in Chennai

Kavi said...

I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
Mobile App Development Company
Mobile App Development Company
Mobile app Development Companies

john stany said...

This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things...

Android App Development Company

Sharon Sandy said...

great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
Web Design Development Company
Web design Company in Chennai
Web development Company in Chennai

louis philip said...


You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
Fitness SMS
Salon SMS
Investor Relation SMS

isabella jacob said...

it is really amazing...thanks for sharing....provide more useful information...
Mobile app development company

john stany said...

These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
iOS App Development Company