Map Making - Location Sensor (Part 1)
Published on February 24, 2022
In this series of guides, we will create maps with LocationSensor and Map components in App Inventor. This is part 1 of the tutorial - we will learn how to use LocationSensor to get our latitude and longitude, and some extra information about how to use it and some precautions.
π·οΈ Tags: #tutorials-and-guides, #maps
Step 1. Setting Up Your Project.
Create a project, give it a suitable name.
From the Palette, drag out a Label (User Interface) and a LocationSensor (Sensors). You do not need to clear the Label's text - we are going to change it in the Blocks anyway.
Click on LocationSensor in the Components list. You will see that it has 3 properties: DistanceInterval, Enabled and TimeInterval.
Enabled specifies whether the location service should be enabled or not. We definitely need this enabled.
TimeInterval specifies when the LocationSensor should be refreshed after a specific time. For example, if the TimeInterval is 1000, the LocationSensor will attempt to refresh the current location after 1000 milliseconds (1 second), but there is no specific guarantee that the co-ordinates detected will definitely be different.
4. Change the TimeInterval to 1000.
5. Head to the Blocks editor.
Step 2. Blocks Editor.
If you use the LocationSensor, you will see a dialog asking you for the permission to access location at the start of the program. If the user denies that, we will set the Label's text to "Location permission denied!".
When the Screen initializes, we will set the Label's text to the latitude and the longitude. If the sensor is still initializing or detecting, Latitude or Longitude will return 0 until it gets a result.
When the location has changes, we will set the label's text to the updated result.
Know Issues With the Location Sensor / Others
Here are some known issues about the LocationSensor and some bugs in it, also how to avoid them.
Some More Customizing!
Not just latitude and longitude, the LocationSesnor also provides altitude and speed data. Try them to learn more!
Β© Gordon Lu π§ E-mail π¬ Message π Phone call