tags:

views:

11053

answers:

4

I need to my current location using GPS programmatically. How do I do that?

+14  A: 

Here is the overview of location services in Android. Here is the LocationManager class at the heart of location services in Android.

Unfortunately, it does not appear that Android ships with any examples of the location API, which is somewhat surprising.

You can download the source code for one of my books -- look for the Internet/Weather and Service/WeatherPlus demos, each of which uses LocationManager. Or, you can download the source for another of my books -- look for the 23-Location tutorial for some examples of using LocationManager. Most of the other online tutorials are out of date, though Reto Meier has one that should be current (and I'm sure this stuff is covered in his book as well).

Unfortunately, you cannot just ask Android for your current position, since GPS may take quite some time to get a fix. Instead, you need to request location updates and use the first update you get, or similar patterns.

CommonsWare
Your books are great!
TTT
Is there a way to buy your book without signing up for a yearly subscription? I was getting frustrated on your site.
Greg
@Greg: You could get a subscription, download the PDFs, then promptly cancel and forget you have a subscription.
Nick T
+10  A: 

Here is complete tutorial

sbidwai
+3  A: 

Using GPS to get current location at : http://www.firstdroid.com/lang/en/2010/04/29/android-development-using-gps-to-get-current-location-2/

ido