LocationSensor doesn't work at all! (on an Android 11.1)

Hello,
I actually have a problem using LocationSensor : the app I made is like trying to calculate my location forever but seems to fail !
I use labels to show the latitude, longitude and altitude, a map and a marker to show my current location. Here are screenshots from the blocks and the properties of the map and of the location sensor components.
When I try my app with AI Companion or installing the APK, it doesn't work at all ! The map and markers never show my location ! I don't understand.
Can anyone help me please ?

loacationsensor_properties blocks

Welcome Augustin.

Try this example

Did it help?

If not, try thisVeryVerySimple_Map.aia (3.2 KB)

Hello, I just figured out the problem : it seems to don't work when I use the gps whereas it works perfectly if I set the providerName to network so it uses Wi Fi and 4G of the phone. But I will do look at your linked project. Hoping the gps will work with your helpful tips because if you are on a top of a mountain with no 4G... The gps must work !:joy: thanks. Augustin

The LocationSensor and gps will always work (they do not require a wifi or network connection to provided geocoordinates; they use your device gps receiver and will work on a top of a mountain). The Map, however is dependent on either WIFI or network . It can only render if you have an internet connection. (Actually an app using Map will cache OpenStreetMap tiles for areas you have 'visited' and render an image but not always a quality map image).

Good luck.

To understand how this stuff, please read Using the Location Sensor if you have not already done so.

Yeah I know that but I tried your VerySimpleMap and that also doesn't work ! Keeping the app opened during 5 minutes, it doesn't find a satellite.:no_mouth::no_mouth: Either I don't have any satellite where I am (that seems strange) or... Idk. Google maps successfully locate me if I disable WiFi/network after 30 seconds. So it's strange...

Are you inside a building?
You might want to test outside to get a good GPS signal...

Taifun

Please try Taifun's suggestion.

Did you read and try the tutorials in post #3 and do the two tutorials in the Using the Location Sensor link? There are always satellites every where on earth, even in the French Alps. Did either of the two examples shown there work? Living in a mountain valley can give a gps receiver issues (because the mountains will block some satellites, however you say

It is possible that Google maps is either using cell tower information to provide a location instead of the gps or your Android is defaulting to WIFI. Can you explain what you mean by 'disable WiFI/network after 30 seconds'? What happens if you use the Google Navigate app? Does it locate you properly?

What version of Android are you using?

So, I'm using Android 11.1 (last release). As you can see in the video I made, I first disable Wi-FI search localisation and then I locate me with Google using only the gps and it works !

Sorry you still cannot get the gps App Inventor app to work. :cry: I have never seen this problem reported before. What do you see on your Android screen when you run the app?...what happens when the app fails (anything you can describe Augustin?). Did you test the app outside?

Be aware, it might take 30 to 60 seconds for the gps to aquire a satellite fix so it could be that long before you get coordinates and a map image.

Since the app is failing on an Android 11.1 I expect the problem might be a permissions issue. Sorry, I cannot test only having an Android 8.1.

Possibly a permission Block is required to use the LocationSensor with an Android 11.device as described : 请求位置信息权限  |  Sensors and location  |  Android Developers.

Someone with an Android 11.1 device needs to test

.. @TIMAI2 ..can you help test this on an Android 11? If the app does not run on an Android 11 the missing required code to make it work might look something like:

locationPermission

I now tried @SteveJG's very very simple example and it works for me on a Samsung A51 running Android 11

preconditions are:

  1. GPS is enabled and
  2. you are outside or at a window to get a good GPS signal and
  3. you are a little bit patient to get a signal after around 30 seconds

@Augustin_Schwerer what do you get for Available Prociders and ProviderName?.
Unbenannt

Taifun

So I tried again with the permission you told me and more outside and IT WORKED !!
BUT the altitude is not very specific and is 50 meters wrong...

:slight_smile: Thank you for being persistent and posting your results. Glad we discovered the issue by working together with Taifun's hints. Congratulations. The main issue was getting outside.

Regarding altitude, what you experience is normal

...from the location sensor tutorial

Altitude

The units is meters. The altitude is the altitude above the WGS84 reference ellipsoid, not the elevation above mean sea level. Altitude from a GPS is terribly inaccurate, even for expensive GPS receivers. Read about altitude determination here: http://gpsinformation.net/main/altitude.htm. Altitude is very unreliable on most GPS receivers, not only those embedded in phones and tablets. Altitude reported on a phone/tablet can easily be off by +/- 30 meters or more!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.