Android GPS takes some time to be precise

I made an Android app that gets the location in longitude and latitude with the click of a button.

First, I get the last known location, which is inaccurate for argumentation, when I first download the application / enable gps.

What I would like to know is to wait until it is accurate, for example, on Google maps, when you receive the message โ€œWaiting for location.โ€

If you see any way that can be improved, it will also be useful.

Code for reference:

public class Clue extends Activity { public static double latitude; public static double longitude; Criteria criteria; LocationManager lm; LocationListener ll; Location location; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.questions); criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); ll = new MyLocationListener(); lm.requestLocationUpdates(lm.getBestProvider(criteria, true), 0, 0, ll); } private boolean weAreThere() { location = getLocation(); longitude = location.getLongitude(); latitude = location.getLatitude(); return inCorrectPlace(param); } private Location getLocation() { lm.requestLocationUpdates(lm.getBestProvider(criteria, true), 0, 0, ll); return lm.getLastKnownLocation(lm.getBestProvider(criteria, true)); } } public class MyLocationListener implements LocationListener { public void onLocationChanged(Location loc) { Clue.longitude = loc.getLongitude(); Clue.latitude = loc.getLatitude(); } } 

Thanks for reading, all answers will be appreciated.

Ben

+4
source share
3 answers

If Location.hasAccuracy() returns true, you can call Location.getAccuracy() to get the accuracy in meters, and then filter out those that you don't think are accurate enough.

Please note that you are not using LocationManager.GPS_PROVIDER so that your corrections can be received in other ways (for example, WiFi).

Usually they wait about a minute for the GPS chip to become โ€œhotโ€ * before receiving GPS corrections (outdoors).

* By hot, I mean satellite coverage. Some chipsets turned off after a while ("cold") in order to preserve the battery. Time to first fix (TTFF) is longer when the chip is cold.

+4
source

Here is a great explanation,

http://android-developers.blogspot.com/2011/06/deep-dive-into-location.html

help you understand exactly how to implement it.

+2
source

Initially, u should get the fix using getlastknownLocation ()

In addition, U can use a background service that updates the location using NETWORK.PROVIDER ... which should not drain the uranium battery when used wisely ... and also works if GPS is disabled.

If you do not have a network provider, you should ask the user to enable GPS.

If ur uses 2.2, try PASSIVE PROVIDER

+2
source

Source: https://habr.com/ru/post/1385513/


All Articles