Bobbie wrote:
> I've posted with no help, please help me out.  I am trying to figure
> out how to get the GPS location of my device.  However, when I use the
> code below (see "CODE TO GET LOCATION") my Android application
> crashes. 

And the error message is...what?

It is difficult to tell you what a crash means without the Java traceback.

You can get this from DDMS or adb logcat.

> LocationManager lM = (LocationManager)
> getSystemService(Context.LOCATION_SERVICE);
> LocationProvider lP = lM.getProvider("gps");
> Location loc = lM.getLastKnownLocation(lP.getName());

At this point, loc is probably null.

> Do I have to somehow tell the GPS to try to get a fix? 

Yes. The device does not keep the GPS radios on all the time, otherwise 
battery life would be worse than it already is. :-(

Try using requestLocationUpdates(). It still may take a while for you to 
get a fix -- I ran a test yesterday and it took ~15 seconds from the 
time my app started until a fix was ready.

This, of course, assumes your device is configured to allow GPS access 
at all:

Settings > Security & Location > Enable GPS satellites

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.4 Published!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to