I need to my current location using GPS programmatically. How do I do that?
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.
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/
Posted my code sample here http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location-in-an/3145655#3145655