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. Order of Axis Values in onSensorChanged

Could one of the Googlers with access to a physical phone confirm the
order of the axis values returned by the on
onSensorChanged event within the SensorListener class?

I assume it's [x, y, z]

Where, for a device lying flat on its back on the table in front of me
in portrait orientation:
The X axis is out of the top of the device.
The Y axis is out the left hand side.
The Z axis is up out of the screen.

Also, is that order the same for the Orientation Sensor (where each
value is rotation on that axis) and the Accelerometer Sensor (where
each value is acceleration in that direction)?
--~--~---------~--~----~------------~-------~--~----~

2. Multiple listeners needed on a subclass of EditText

Hi,

I have written a subclass of EditText that has an
onFocusChangeListener that brings up a keyboard on focus.  I have view
that uses this EditText that needs to register an
onFocusChangeListener on the same EditText.  Setting the listener in
the view kills the listener that brings up the keyboard.

I could extend the listener that calls up the keyboard, call super and
then do my custom listener actions.  But this seems like a very non-
object oriented way of doing things.

What are my options other than what I mentioned above?  Is this not a
legitimate use case to have an add<Listener> instead of a
set<Listener>.

Thanks,

Nik Bhattacharya
Senior Technologist
frog design
--~--~---------~--~----~------------~-------~--~----~

3. NEWS: Android To Capture 4% Of Smartphone Market

4. Any way to send out an image to contacts via Android application?

5. my map isn't dragable

6. Problem with VideoView

7. Problems applying animation to SurfaceView