If you use the Logcat view in Eclipse or the "adb logcat" command from
the SDK on the command line you can see why your app is crashing. In
this case it is probably that getLastKnownLocation is returning null,
which it can as per the documentation:
http://developer.android.com/intl/zh-CN/reference/android/location/LocationManager.html#getLastKnownLocation%28java.lang.String%29

You can't call methods like getLatitude on null. Look at the
requestLocationUpdates methods for a way to get locations that
actually starts up the location provider.

I remember in earlier SDKs you could add mock locations by putting a
file somewhere on the phone. I don't think that is supported any more.
See the note above the "Providing Mock Location Data" heading here:
http://developer.android.com/intl/zh-CN/guide/topics/location/index.html

On Nov 28, 12:03 pm, redants1972 <redants1...@googlemail.com> wrote:
> Thanks for the advice. I am still having trouble however.
>
> When I add the debug line as advised, the app falls over and as far as
> I can tell, 'location' is coming out as null.
>
> If I comment out the log.i code then it works ok. So it seems to me
> that there is something wrong with the way I am trying to get my
> coordinates.
> I'm not sure what I should be expecting when I load the KML file, as
> nothing appears in the panel. It's not clear to me how the loading
> of the KML file or manual coordinates actually link to the line -
>
> Location location = locationManager.getLastKnownLocation("gps");
>
> I thought the "gps" part referred to the folder location under "C:
> \Program Files\android-sdk-windows-1.6_r1\tools\data\misc\location",
> but I could have got that wrong.
>
> Any further advice would be greatly appreciated. I think one of the
> issues here is my inexperience in using the IDE and the way in which
> run time errors can be viewed and trapped.
>
> Cheers,
>
> On Nov 27, 4:55 pm, Neilz <neilhorn...@googlemail.com> wrote:
>
> > Hi. As you are using Eclipse, you can use the Android plug in, and the
> > build in Emulator Control, to load up your KML file and manually send
> > location updates to the emulator. You find it at Window->Show View-
>
> > >Other->Android->Emulator Control. That should get you going.
>
> > To debug:
>
> > import android.util.Log;
>
> > Log.i("MyCLassName", "Lat: " + location.getLatitude() + " Long: " +
> > location.getLongitude());
>
> > Hope this helps.
>
> > On Nov 24, 9:38 pm, redants1972 <redants1...@googlemail.com> wrote:
>
> > > I am trying to produce a mock location provider by using an example
> > > kml file grabbed from somewhere (where I cannot remember now). Anyway
> > > I think I also need a properties file but I'm not sure where this goes
> > > and what it is called.
>
> > > The code I am using is -
>
> > > locationManager = (LocationManager)getSystemService
> > > (Context.LOCATION_SERVICE);
> > > Location location = locationManager.getLastKnownLocation("gps");
>
> > > double lat = location.getLatitude();
> > > double lng = location.getLongitude();
>
> > > It seems that I am not getting anything back from the kml file, but as
> > > a beginner to Android and Java I am struggling to debug the problem. I
> > > am using eclipse Ganymede.
>
> > > What I need really is some pointers on the following:
>
> > > 1. How do I debug so that I can see the values of Location.getLatitude
> > > () and location.getLongitude(); ?
> > > 2. I am referencing "gps" as my provider and have a kml file located
> > > at C:\Program Files\android-sdk-windows-1.6_r1\tools\data\misc\location
> > > \gps . Is this correct?
> > > 3. How do I create the properties file?
> > > 4. Any other advice would be greatly appreciated.
>
> > > I have scoured the net for answers but nothing seems to fit what I am
> > > after. I have also tried to go to 
> > > URLhttp://code.google.com/android/toolbox/apis/lbs.html
> > > but it redirects me tohttp://developer.android.com/guide/index.html
>
> > > Thanks in advance,

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to