问题
Im writing an application that supposed to send coordinates in an SMS, but I've been struggling a bit with understanding how to get the coordinates.
At the moment I'm using this
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
longitude = location.getLongitude();
latitude = location.getLatitude();
And then i pass the long and lat into the text, but this only gives me the last know location i guess?
Can anyone tell me how to get the current location?
Regards /Fred
回答1:
you need to create a LocationListener and pass it to the LocationManager like this: locationManager.requestLocationUpdates(
locationManager.getBestProvider(fine, true),
minTime, 0, listenerFine);
You will get your lat/long updates from the listener in onLocationChanged()
回答2:
Please referred Below Link it may be Help You Get user current position with gps/network android MapView or http://www.vogella.de/articles/AndroidLocationAPI/article.html
来源:https://stackoverflow.com/questions/9880410/get-current-coordinates