Location accuracy sometimes poor (half a mile out) on new phone

Great. :smile:

Google did not implement the 'fused' LocationSensor Provider until about Android 10. Android 8 did not have that feature. :wink: It works the way it does is that is house Google wants users to make use of the 'fused' feature. in apps about Android 10+. Fused Location Provider API  |  Google for Developers . Your old app is six years old. Time and coding rules march on.

Regarding compiling your app for use on Android 13, and building the apk, you will have to have some Blocks like

FineLocation

to allow Android to set the Location permissions. You also need a Clock.TImerEnabled to true Block in your Screen1.Initialize event handler.

You only can set the provider to gps snd lock it if it is available in Available Providers
https://ai2.appinventor.mit.edu/reference/components/sensors.html#LocationSensor

AvailableProviders

List of available service providers, such as gps or network. This information is provided as a list and in text form.

directly in Screen.Initialize it still might be too early to do that...

Taifun

gps is always available if a device has gps hardware. Virtually all newer Androids do.

On an Android 13 the available Providers will probably be

And what happens, if gps is deactivated in the settings?

Taifun

I've just been out on my bike with both versions of the app running (with and without the two extra blocks). Both versions tracked the road I was riding along to within 2 m for several miles. I suspect the problems arise in particular places. Thanks very much for all your suggestions which I will study in detail when I have time, and probably make a third version of the app with the facility for the user to change the location settings.

While you are testing you might try this as well

I am trying to get permission for FineLocation but have not succeeded. The blocks below produce a runtime error and the user is not asked to give permission. The same happens if I put the Call Screen 1 AskForPermission block in the Initialise block. What am I doing wrong??

Something like this ?

Also, your timerInterval needs to be set above your timerEnabled ?

What I do

Remember, you must BUILD your app toe get FineLocation permission. Depending on what ever bells and whistles your app uses, it will need additional code.

I've tried lots of things but nothing works. The best solution is the first from SteveJG which just involved adding two blocks to the initialise block:

It did produce a runtime error when first opened but it was ok next time. And the location jiggles around by up to about 40m - feels like it's coarse location not fine location. I still can't see how to get FineLocation and none of my efforts resulted in the user being asked for permission as the block implied should happen.

Presumably at some stage the AppInventor team will fix this problem? As one of my kind advisors said programming moves on, but it's just a pity that the motion is in the direction of a deterioration not an improvement!

Many thanks to everyone for their help.

Have you tried HTML5 Geolocation ?

This is the way the gps works. Read about Accuracy in Using the Location Sensor. What you get depends on how many satellites are used by the gps to provide a location fix.

Did you build the app? You need to build the app. During the install process the user is given the opportunity to use coarse or fine. Subsequent use, the setting is remembered.

I don't believe there is a problem. The LocationSensor uses one satellite constellation for a satellite fix. Your phone can use multiple constellations but an app built with the present LocationSensor component uses only one. To use more satellites, you can use an extension. As mentioned previously, Accuracy depends on many factors. Typically Accuracy is 10 m , occasionally 2 and up to 40 m or so.
Not happy, filter out satellite fixes that are more than 20 or whatever.

1 Like

In addition to all have been already said, please consider that there is a very good extension made by @Juan_Antonio ( :+1:), called "com.KIO4_NmeaMessage.aix"
(You can find it on his "KIO4"web site).
I've used it to get raw data from the GPS sensor as fast as possible (the related accuracy depends anyway on how many satellites are linked).
By using this extension and by parsing the NMEA183 message you can extract the data you need (i.e. Lat, Lon, Time,.......).
Best wishes.

1 Like

Yes, but the error is occasionally up to half a mile! I've got one comment and two questions.

(1) My app works perfectly with Android 8.1, but not Android 13? I appreciate that Android 13 does something differently, but it seems a pity that it's worse than the previous version.

(2) There is an AskForPermission block which I have tried to use. But I, as the user, have never been asked for permission, which suggests to me this block is not working.

(3) Why isn't there a SetPermission block in App Inventor?

It looks like you did not follow the suggestion from @SteveJG here

You still set the provider name to gps in the Screen.Initialize event, which is wrong, because you only can set it if it is available as already mentioned earlier...

What about providing an updated screenshot of your relevant blocks?

Google 'improves' Android from version to version mostly because of security reasons

You will have to test using the apk file

This is the concept of Google... apps can't just set permissions they need, apps have to ask the user for permissions...

Taifun

Also you might want to check both the provider name and accuracy on each location changed event

http://ai2.appinventor.mit.edu/reference/components/sensors.html#LocationSensor

Accuracy

The LocationSensor will be able to locate the device with a varying degree of confidence, based on the quality of satellite, cell towers, and other data used to estimate location. The Accuracy value is the radius in meters around the sensor’s detected location. The device has a 68% chance to be located within this radius. More precise location detection will result in a smaller accuracy number, which allows the app to have more confidence where the device is actually located.

If the accuracy is not known, the return value is 0.0

ProviderName

The current service provider. The provider will most likely be either GPS or network.

You probably think you are using gps, but actually are using another provider, for example fused location... also depending on the location the signal might be poor... probably in a forest or between tall buildings... here it helps to check the accuracy...

Taifun

Aa a test you also can try my locationservice example project, documentation is here App Inventor Extensions: Location Service | Pura Vida Apps

Example project downloadable from Google Play here
https://play.google.com/apps/testing/appinventor.ai_taifunbaer.locationservice

Taifun

Thanks (Taifun) for these comments. I like your use of the word "improves", but it is frustrating that what works on an earlier version doesn't on the latest version! An error of half a mile (only occasionally) is not trivial.

I was wrong about not being asked for permission for Fine Location. I was expecting it to ask every time I ran the app, but it only asks the first time and I assumed it was part of the installation process. (I'm doing all the testing with an apk file on the phone.)

I've tried lots of thing and I think the winner at the moment is my original app with these extra blocks (although there are too many variables to be sure):

However, there is still an error of up to about 20m which is not as good as Android 8.1.

Therefore

to find out why
Taifun

That sounds like an excellent idea which I will try if/when I have the patience.

However, yesterday's trial was sitting on a bench by a pond in a town. Today I tried sitting on a broken tree trunk in a wood and the results were very different. Yesterday's winner had me 500m north of where I actually was, followed shortly by 2000m east (more than a mile)!. And it didn't budge. The new winner which was close (within about 50m) was the original app with just two extra blocks:
image

If only Google would stop their "improvements". No problems with Android 8.1.

1 Like