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. Drawing a Nine Patch image

Hi all. I'm trying to create on of these images, but Eclipse won't
accept it once I've used the draw9patch tool.

I've found other people having the same problem, and saw this comment:

..."I discovered later that the problem I was having was caused by
the image not being exactly true to the nine-patch spec as defined in
the documentation.  Once I fixed the image to have a clean (i.e., no
gradients etc) one pixel border it was fine. "

I'm not much good when it comes to image design. What does this mean,
how do I create my original png file to meet the specification for
Nine Patch?

-- 

2. Intents for google maps

Hi all

   I am developing a android project named " Smart Google Maps ".For
my App, I need to use Google Maps Application which is built in with
Android SDK 1.6.I need to call google Maps from my App. How could I do
that?

I am able to use call Phone dialer using intents from my
Application.But I am unable to do it for Google Maps.
I did'nt find any intents for google maps to call GoogleMaps from my
application.
Can anyone suggest me solution for this? Its is my term project and
dead stuck with it?

Regards
Sreekanth Nambu

-- 

3. Android Manifest Error, and SMS Sending Program.

4. SlidingDrawer Widget

5. how to create this layout

6. Problem with starting an activity when pressing button in menu.

7. Problem with starting an activity when pressing button in menu.