How i can get the latitude and longitude of the current location, from android?
Asked
Active
Viewed 5,094 times
2
-
1possible duplicate of [What is the simplest and most robust way to get the user's current location in Android?](http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location-in-an) – MarkJ Oct 05 '10 at 13:10
-
Here's your answer: http://stackoverflow.com/questions/3145089/what-is-the-simplest-and-most-robust-way-to-get-the-users-current-location-in-an/3145655#3145655 – Edi Oct 05 '10 at 10:47
-
+1. In fact I'm voting to close this question because it is an exact duplicate of that other question. – MarkJ Oct 05 '10 at 13:10
-
I wouldn't say it's an exact duplicate, because that question is asking how to get the location, this is asking for lat/long specifically. Granted, location gives the lat/long when you ask for it, but still. This is like another step that they don't cover. – Brandon Jan 28 '11 at 22:47
1 Answers
3
you can use the LocationListener class to get the coordinates while on the move.
use the following to get the coordiates when not on the move.
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(location == null){
LAT = 0.0;
LONG = 0.0;
loc.setText("No Location");
}
for an indepth discussion --
-
Getting null pointer Exception while use location.getLatitude();location.getLoongitude(); – mohammedsuhail Oct 05 '10 at 10:44
-
you probably haven't pushed the lat and long from DDMS. anyway can you post your code. – Umesh Oct 05 '10 at 10:56