Location coordinates not generating properly

Hi,
I am Joel and I am very new to using MIT APP Inventor. I am making my first fruit ordering app. Here is my block

My Clock1 timer interval is set at 1000(default). The LocationSensor1 is enabled and has a timerinterval of 60000(default)
The coordinates don't generate sometimes and return as 0, 0
Is there something I am doing wrong?

Thank you

Joel

LocationSensor may not work inside room. Have you tried at outdoor/open roof?

This means you request the gps to update once every 60 seconds. I recommend you update at 30 or 20 second intervals (use the LocationSensor1.TimerInterval Block and set it to 30000 ms). If you follow Kevinkun's advice, your coordinates may generate as you expect. You also might not be waiting long enough for the Location sensor to determine where your device is at before you press your submit button. :cry:

0,0 is the default coordinates received when a satellite fix has not been determined..

Have you read Using the Location Sensor and the documentation LocationSensor ? Together, they explain how gps works.

Your Label1 might require the location in the form xxxx,xxxx (with a comma separating the latitude and longitude ) and not xxxx xxxx (separated by a space). The comma might be needed when you use the Label1 in the Web1.Url
comma

Thank you Kevin and Steve :smiley: Personally I am able to get coordinates at my home, but my friends who are helping with testing my app, their submission shows as 0, 0. Kevin, like you said one of my friend did go outdoor and his submission did record lat and long. But my other friend's submission still shows 0, 0. Steve, I did add a coma and space to lat long, but somehow it got deleted when trying location sensor. And, like you said interval might also be one reason other than outdoor because my other friend selects the fruit in a jiffy and submits it too fast before the location sensor is able to determine the address. Here is the updated block.


Is this correct way of setting interval at screen initialize? Also, my default timer interval at designer is still 60000 and there is no way disable it. Should I leave the 60000 interval as is in designer block and continue setting the LocationSensor1.TimerInterval Block at screen initialize to 30000? Thank you both of you for the recommendations. :smiley:

property setter in blocks will override the one in designer.

Yes. Set the TimeInterval early in the Screen1.Initialize stack (see Kevinjun's post).

This can be handled in the Submit Button event handler.

If LocationSenor1.Latitude =not 0 and LocationSensor1.Longitude =not 0 then do the submittal else use a Notifier to tell the user to try again in a few seconds. This prevents someone jumping the gun before the device decides where it is at.

Hopefully app is working better. Other factors influence how quickly a device will get a satellite fix (Android version, cpu software, whether you are also connected to a Map component etc. but you now have the main issues covered :slight_smile: )

Thank You Kevin and Steve :smiley: I have set locationsensor interval to 30000 in screeninitialize. I have added the suggestion of If LocationSenor1.Latitude =not 0 and LocationSensor1.Longitude =not 0 then Submit enabled to true else call notifier to tell the user to try after few seconds. See here -


. But it is still getting submitted immediately on clicking submit. I know I am doing something wrong :sob: Can you please correct me...

  1. set btnSubmit.enable to false in designer.
  2. in LocationSensor.LocationChanged event, if latitute <> 0, then set btnSubmit.enabled to true.

Kevin, I disabled submit button in designer and in LocationSensor.LocationChanged event, if latitude <> 0, then set Submit.enabled to true. See the blocks -

I tested this build in my mobile, now I unable to submit(the submit button stays disabled).

of course, you have to wait until locationSensor got a location.

To exclude 0,0 you need code like one of these:

depending when/where you are checking for the device to indicate it is reporting its location.

There are several ways to either disable or limit use of it (see Kevinkun's comments).

Perfecto. I am so happy. By combining both your solutions, it is working now. Thanks a lot Kevin and Steve :smiley: :smiley:

1 Like