julien coustillas

unread,
May 24, 2018, 5:43:27 AM5/24/18
to MIT App Inventor Forum

Hello everyone, 

 I am using App inventor since 2 days and I find it pretty amazing. I am stuck with a location sensor problem. 
I have already read a lot of topics about it but not able to find a solution. (I am sure it will be pretty obvious). 

My problem : 
I added the location sensor to my project and I am using the block  "when location changed " to update label. 
But I always get 0. 










What I have tried: 
I changed the interval to 60000 in the screen init
I checked gps is activated and authorized for mit app 
On google map my position is good.
I download and tested the SmpleGPS.aia file. But nothing is updated. 

My environment: 
using USB debug. 
Huawey Honor 8. 

Thanks for your help. 


(sry french) 

    



SimpleGPS.aia

SteveJG

unread,
May 24, 2018, 8:05:10 AM5/24/18
to MIT App Inventor Forum
If you load the SimpleGPS.aia without modification, what happens?   It runs fine here using either Companion or building the apk.

You have coded this:

Perhaps you intend to set lat_value.Text to get latitude?   

If both latitude and longitude values are 0, it means the GPS has not obtained a satellite fix.   Are you in a building without windows? The initial satelite fix will take 20 to 40 seconds or more; subsequent fixes occur more rapidly.

If you load the aia, what does a screen capture of the screen look like? You said "I download and tested the SmpleGPS.aia file. But nothing is updated. "   Nothing is updated?  Does it show  true - true if device has a GPS?

Perhaps this is an issue of the Huawey Honor 8 while using USB.   Have you built the apk and installed the app?  You might try that and take your phone outside.

Regards,
Steve

julien coustillas

unread,
May 24, 2018, 8:24:48 AM5/24/18
to MIT App Inventor Forum
When I load the SimpleGPS.aia, absolutely nothing happens. 
The text labels do not change and stays "Text for labelx", I waited for several minutes and also clicked on the "Test now" button.
I tested on the Companion and a deployed Apk.  

But I found the problem, you were right to repeat to try outside. 
I work in an indoor environment so I tried outside and it worked, with a good accuracy.
It was pretty obvious but I could not believe it. How my other apps can work in indoor with GPS (like google maps)  and not this app ? 

Thank you for your help 

SteveJG

unread,
May 24, 2018, 9:04:23 AM5/24/18
to MIT App Inventor Forum
Thanks, glad outside worked.   To get the app to work indoors, you might try placing the following block




within your Screen1.Initialize block. It tells your device to use all the Providers.  You may also need an initialize global providerList to createemptylist block to initialize the Provider List.   If network is set and you have the following Settings,


I imagine your device might work indoor susing the Provider setting in the block  but it might only work if your Android is connected using WIFI, not USB.  passive only works on cell phones, not tablets without sim cards.

  1. gps –> (GPS, AGPS)
    Name of the GPS location provider. This provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix. Requires the permission android.permission.ACCESS_FINE_LOCATION.
  2. network –> (AGPS, CellID, WiFi MACID)
    Name of the network location provider. This provider determines location based on availability of cell tower and WiFi access points. Results are retrieved by means of a network lookup. Requires either of the permissions android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
  3. passive –> (CellID, WiFi MACID)
    A special location provider for receiving locations without actually initiating a location fix. This provider can be used to passively receive location updates when other applications or services request them without actually requesting the locations yourself. This provider will return locations generated by other providers. Requires the permission android.permission.ACCESS_FINE_LOCATION, although if the GPS is not enabled this provider might only return coarse fixes.

If you try using the block , please let us know what happens.  This seems to work on my tablet.

-- Steve


julien coustillas

unread,
May 24, 2018, 11:07:01 AM5/24/18
to MIT App Inventor Forum
Thank a lot 

It works perfectly in USB debug when I set the providername to "network" during the screen init. 
however I didn't get how to use your providerList, except I if I want to allow the user to switch provider. 
But I would like to know why it comes back on GPS after a certain time or when I set the locationsensor.enabled to True. 

Thank you again for the Tip ;)

Julien 

SteveJG

unread,
May 24, 2018, 11:30:10 AM5/24/18
to MIT App Inventor Forum
 Thanks for testing and confirming setting network (or a list of providers containing network) allows you to work indoors (without the gps).  If you use the Provider List, the LocationSensor should select automatically among what is available. It appears that it does that and gps activates when it has a signal. Yes, you may be getting a hardware GPS signal from the receiver in your device occasionally even though indoors. The precision of a LocationSensor query is, best to worse   gps   .... network ....passive.   The Accurracy will be best with gps normally and is less precise with network and least precise with passive.




The Provider can be set to a List of Providers   when you use a providerList  or forced to gps or network by choosing the appropriate  set LocationSensor1.ProviderName to .... Realize, this is not perfect, what happens depends on the selections made  in the Location Settings on the device.  The device Location Settings cannot be changed with code.  With os 4+ Google made that impossible to close a security hole.


--Steve




Reply all
Reply to author
Forward
0 new messages