Android Question FusedLocationProvider question

SeaBee

Member
Licensed User
I have implemented FusedLocationProvider in my app, but I want to separate location services from GPS. Since, for the most part, GPS need not be used, and in the interests of saving battery power, the default would be location services, but should there be no internet access, then I want to fall back to GPS, and also separately offer a direct GPS access if the user requires higher accuracy, without going first to location services.

Being a creature of very little brain (thank you A. A. Milne), I do not see how I can control just location services or just GPS, and any pointers will be gratefully received. Both ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION are permitted in the manifest, although I may make ACCESS_FINE_LOCATION optional later.
 

SeaBee

Member
Licensed User
Thanks very much for your reply. I didn't realize this would do the job, thinking it was not a rigorous setting, and could be overridden by the OS if it was deemed appropriate.

Also thanks for the tip about permissions - I will leave it as it is.

Thanks,

Chris C-B
 
Upvote 0

SeaBee

Member
Licensed User
Now I have got my system back over the catastrophe, I'm back to B4A, and following up on the solution provided by Erel, and I find another stumbling block.

Using Vader Consulting's excellent 'B4A Object Browser', I see there a FusedLocationProvider.Priority item, which does not appear when used in an application. In fact, the two sets of available options are remarkably different.

So, how do I implement FusedLocationProvider.Priority.PRIORITY_HIGH_ACCURACY ?

Can anyone help, please?

Chris C-B
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
So, how do I implement FusedLocationProvider.Priority.PRIORITY_HIGH_ACCURACY ?
Check the documentation!
https://www.b4x.com/android/help/fusedlocationprovider.html#locationrequest_setpriority

Priority

Events:
None
Members:

Field.png
PRIORITY_BALANCED_POWER_ACCURACY As Int

Field.png
PRIORITY_HIGH_ACCURACY As Int

Field.png
PRIORITY_LOW_POWER As Int

Field.png
PRIORITY_NO_POWER As Int

Members description:

Field.png
PRIORITY_BALANCED_POWER_ACCURACY As Int

Used with SetPriority(Int) to request "block" level accuracy.
Field.png
PRIORITY_HIGH_ACCURACY As Int

Used with SetPriority(Int) to request the most accurate locations available.
Field.png
PRIORITY_LOW_POWER As Int

Used with SetPriority(Int) to request "city" level accuracy.
Field.png
PRIORITY_NO_POWER As Int

Used with SetPriority(Int) to request the best accuracy possible with zero additional power consumption.
 
Upvote 0

SeaBee

Member
Licensed User
Thanks very much for the explanation. What I didn't realize is that I need to declare a LocationRequest first, and set the priority to this. Now I have reread all available stuff on the FusedLocationProvider and understand it a lot better, I shall continue to get the LastLocation (working fine) and check it's time and accuracy. If these meet the requirements, then just proceed, otherwise offer LocationServices or GPS, and let the user decide. Once a satisfactory result is obtained, turn it all off!

Again, thanks for the rapid support.

Chris C-B
 
Upvote 0

SeaBee

Member
Licensed User
Murphy's law strikes again! Having got FusedLocationProvider working precisely as I want, and in a fairly complex manner, I now think I am going to have to dump it, and go with direct GPS and esLocation2.

I got around to reading the Google Play API licence agreement carefully, and find that, for the purposes of my app, I cannot save the data, not even for the 30 day waiver, as the FusedLocationProvider is part of Google Play API. This is a big problem, as the app facilitates planning future events, and I need to save this location's position. Geocoding is a much harder nut to crack. If the user puts in the relevant place name, Google Play returns a list of possible locations, and on selection, the user gets the latitude and longitude of the location, which I then need to save, but cannot save under the licence agreement.

My current possible workaround is desperately complex, and is based on the fact that although the raw data cannot be saved, the product thereof can be saved. I am an amateur sailor, and years ago, before even Transit satnav was available, I wrote a permanent almanac in HP basic for the HP95C, giving a sextant user the ability to navigate without the complexity of using Admiralty tables and written calculation sheets. My permanent almanac provided full data on the Sun, Moon, the six navigational planets, and the 63 navigational stars (but not allowing for the proper motion of the stars, as this level of accuracy was not required).

I have already started looking at a B4A transfer of this for just the Sun - the easiest to compute. My planned methodology here is to calculate the precise altitude and azimuth (just N or S) of the sun at transit, at the location and at 0 N and 0 W, on the date the location was researched on Google. I will store this data only (place name, date of search, alt. and az. Sun, alt. and az. 0,0). Then, subsequently, when the user wants to review data for that location, the latitude and longitude may be easily reconstituted and saved, being 'the product thereof' of the Google API.

What a palaver, just to save two numbers! :eek: :( :mad:
 
Upvote 0
Top