How to get current location with an accept accuracy in Android
Posted
by virsir
on Stack Overflow
See other posts from Stack Overflow
or by virsir
Published on 2010-06-08T08:49:36Z
Indexed on
2010/06/08
8:52 UTC
Read the original article
Hit count: 302
I am trying to locate user's device to get its current location with coarse method. The problem is that I can only accept a location with accuracy of 1000m, my code like this:
public void onLocationChanged(Location location) {
currentLocation = location;
if(location.hasAccuracy())
{
if(location.getAccuracy() < 1000)
{
locationManager.removeUpdates(this);
callback(); //do callback here
}
}
}
But what if the network is not good and I can not get the location with that accuracy? I may want to accept the latest location I got if I have requested its location for some time, like 1 minute.
Then how can I control the request time, for example, 1 minute, if it did not get the accurate location until then, I will stop it and then accept the latest location I have got if exist.
© Stack Overflow or respective owner