简体   繁体   中英

How to properly get an accurate location using fused location

I am working on a shopping app, after the shopping is done you proceed to provide a location for delivery.

Here i have multiple questions just guides as i couldn't find a reliable answer for my questions:

1)is fusedLocationProviderClient the best way to do it? And is its accuracy enough? Or i need to keep checking for accuracy?

2)what method does whatsapp app uses? you can get down to 5 meters accuracy by just waiting the map to load more, how could that be done?

3) if i need only location for delivery, does that mean i should use last Known Location or i must use location updates.

Thanks in advance for your guide as i am a beginner.

1) Yes, FusedLocationProvider is the best option for more than 1 reason. You can always use the LocationManager, but then your app will be listed as a high battery use location app in the 'Recent location requests' section. Also, LocationManager will have to wake the GPS chip exclusively for your app instead of possibly reusing location data that the system already has. As for accuracy when using FusedLocationProviderClient , set the priority to PRIORITY_HIGH_ACCURACY and fast interval to about 100ms when you setup the LocationRequest . See LocationRequest for details.

The accuracy depends on the frequency of the request (fastest interval) and the source. The source will be selected automatically depending on the priority you set. If you set a PRIORITY_NO_POWER it may just use cell tower data to give you city level accuracy, but if you set PRIORITY_HIGH_ACCURACY it will use the GPS chip to get maximum accuracy. It's always a compromise between battery usage and the level of accuracy you need. Eg:

locationRequest = new LocationRequest();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(UPDATE_INTERVAL);
locationRequest.setFastestInterval(FASTEST_INTERVAL);

2) Not sure what Whatsapp uses - it could be either. You can achieve 5m accuracy (Commercial GPS chips on modern phones can go upto 1-3m accuracy) by either method by setting the location provider to high accuracy mode. However, Google recommends using Fused Location.

3) Last known location is not guaranteed to be accurate nor is it guaranteed to be non-null either. It provides the 'last known' location that the device managed to get while in use. This may be outdated and inaccurate. So if you need an accurate location you absolutely need to get location updates.

See this on how to start using FusedLocationProviderClient for continuous location updates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM