Getting GPS Location Crashes

by Bobbie » Wed, 05 Nov 2008 23:32:40 GMT


Sponsored Links
 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.  I am developing on the G1 phone.  If I change the provider
to "network" instead of "gps", it works perfectly fine.  Here is the
code I am using:

** ANDROID MANIFEST PERMISSIONS **
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission
android:name="android:permission.ACCESS_FINE_LOCATION" />

** CODE TO GET LOCATION **
LocationManager lM = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
LocationProvider lP = lM.getProvider("gps");
Location loc = lM.getLastKnownLocation(lP.getName());

Do I have to somehow tell the GPS to try to get a fix?  If so, how do
I go about that?
--~--~---------~--~----~------------~-------~--~----~



Getting GPS Location Crashes

by Mark Murphy » Wed, 05 Nov 2008 23:41:05 GMT


 


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.


At this point, loc is probably null.


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!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. how to rotate quad around its center

Hi guys!
I'm a newbie in OpenGL. :D
I'm trying to rotate a quad around its center.

This is my scenario: I've a quad, drawn with TRIANGLE_STRIP, at
specified coordinates. Now I want to rotate of 45 degrees around its
center, without move it from its position, not around the origin of
the aces.
I hope you are able to understand my english... :)

How can I do that?

Thanks

Paolo

-- 

2. Resolved: Making TextViews Spannable causes ListView performance to tank

After pulling my hair out for hours ...it turns out performance only
degrades when the de{*filter*} is running! I'm guessing the de{*filter*} has
always dragged down performance for obvious reasons and my text
processing in this case pushed it over the edge where the de{*filter*}s
effect became noticeable? Either way I'm happy. It's still smokin'
fast on fling. :-D

Hopefully this helps someone down the road seeing similar behavior!

-Stace





-- 

3. how to launch applications installed in a phone?

4. Video Conferencing on HTC EVO

5. WTPamer : jerman vs serbia on motod roid鈩

6. Getting text of dynamically created radio buttons

7. Problem with cursors