Location Blocks
Last updated
Last updated
In the world of mobile app development, location-based services have become a cornerstone of innovation, offering endless possibilities for creating engaging and practical applications. The Thunkable location blocks connect to the Google Maps APIs to create location-aware apps that enhance user experiences and improve engagement.
The get current location
returns a user's current location in latitude
and longitude
as well as a location
object which includes additional properties like accuracy
, altitude
, speed
and heading
(or direction) which you can retrieve with theget property of object
block.
Enables network provider that uses Google Play services to improve location accuracy and location-based services.
Theset high accuracy location enabled to
block sets whether the high accuracy location is enabled or not.
Thehigh accuracy location enabled
block returns true
or false
value for whether the high accuracy location is enabled.
Location updates blocks allow you to easily monitor a user's location in real time. By starting and stopping location updates, you have full control over when tracking occurs, and you can trigger specific blocks when the user's location changes. You can also check the current status of location tracking to ensure it's active.
The start location updates
block begins tracking the user's location.
The stop location updates
block ends tracking the user's location.
When location tracking is active, the when location changes
block will be triggered automatically whenever the user's location changes. The when location changes
returns a user's current location in latitude
and longitude
as well as a location
object which includes additional properties like accuracy
, altitude
, speed
and heading
(or direction) which you can retrieve with theget property of object
block.
The location updates active?
block returns true
or false
value for whether the location updates is enabled.
Prior to publishing an app that incorporates the following Thunkable location blocks, you must first enter your personal Web API Key in your project's app settings. You can web preview and live-test your app with the Thunkable Live app using Thunkable's Web API Key, but you need to provide your own in order to publish your app.
To add your own Google Maps Web API Key to your Thunkable project:
Follow these instructions to create your Web API Key: Creating API keys.
Click the gear icon on the left of your Thunkable project's Design tab to access your Project Settings.
Scroll to the Google Map Settings section.
Input your Web API Key into the corresponding field.
Geocoding is the process of converting an address to a latitude-longitude pair. To access this functionality in Thunkable, you use the coordinates from address
block in the Location drawer of blocks.
Outputs:
latitude
longitude
error
For Android, geocoding requires the device’s location services to be enabled.
In the sample block combination below, when the Geocode button (btnGeocode) is clicked, the coordinates form address
block will geocode the address the user has input in the text input (textAddress), and output the address’s latitude and longitude or an error if applicable. If there is an error, the label (labelError) will populate with the error output text. If there isn’t an error, the label (labelLocation) text will be populated by the address’s latitude and longitude, separated by a comma.
Additional error values are available here: Google Maps Platform Status Codes.
Reverse Geocoding is the process of converting a latitude-longitude pair into a human-readable street address or Plus Code. To access this functionality in Thunkable, you use the address from coordinates
block, which is in the Location drawer of blocks.
For Android, reverse geocoding requires the device’s location services to be enabled.
In the sample block combination below, when the Reverse Geocode button (btnReverse) is clicked, the address from coordinates
block will engage in reverse geocoding using the latitude and longitude the user has input in the text inputs (textLat and textLng), and output the coordinate’s address or an error if applicable. If there is an error, the label (labelError) will populate with the error output text. If there isn’t an error, the label (labelAddress) text will be populated by the latitude and longitude’s address.
Note: The address from coordinates
block in the image above is the advanced version of the block. To access this version:
Drag and drop the block into your workspace.
Right click on the block.
Select Show advanced block.
Additional error values are available here: Google Maps Platform Status Codes.
If a street address is unavailable, the block may return a Plus Code.
Creators can utilize the search places blocks in their projects to allow their users to search Google Maps for places, businesses, and points of interest using text-based queries. For example, users can search for things such as “pizza restaurants in San Francisco” or “123 Main Street.”
The search places blocks leverage the Google Maps Text Search API, which allows you to send a search query as a string of text, and then Google Maps returns a list of places that match the query, along with relevant information like place names, addresses, and other details.
This block only requires the user’s query input. The API considers places based on the query's relevance.
This block is built as an advanced-only block. It allows Creators to include additional inputs and provides additional outputs.
Notes:
If neither latitude nor longitude values are provided, it will not pass the location parameter in the call. If only one of those values is provided, it will still pass the location parameter (but expect that the response will include an error or ignore it).
The location parameter may be overridden if the text query contains an explicit location, such as Market in Barcelona. Using quotes around the query may also influence the weight given to the location and radius.
Have feedback on this doc? Please take a moment to share your feedback here: Thunkable Docs Feedback. Your valuable insights will help us improve and better serve you in the future.
Returned Value | Explanation |
---|---|
Returned Value | Explanation |
---|---|
Input | Description |
---|---|
Output | Description |
---|---|
ZERO_RESULTS
The request was successful but returned no results.
INVALID_REQUEST
The request was not successful due to invalid parameters.
E_LOCATION_UNAUTHORIZED
Location services must be enabled.
ZERO_RESULTS
The request was successful but returned no results.
INVALID_REQUEST
The request was not successful due to invalid parameters.
E_LOCATION_UNAUTHORIZED
Location services must be enabled.
latitude
The geographical coordinate (in decimal degrees format ranging from -90 to 90) that specifies the north-south position of a location on the Earth's surface, measured in degrees from the equator.
longitude
The geographical coordinate (in decimal degrees format ranging from -180 to 180) that specifies the east-west position of a location on the Earth's surface, measured in degrees from the Prime Meridian.
radius
A parameter that defines a circular area (in meters) around a specified latitude and longitude, within which the API should search for places based on the provided text query. If the radius is not specified, the API will consider places across a wider area based on the query's relevance.
language
An optional parameter that specifies the preferred language for the results, ensuring that place names, descriptions, and other information are presented in the user's preferred language. See here for a list of supported languages: Google Maps Platform - Supported Languages.
page token
A token provided in the API response, which can be used to retrieve additional results from a previous query in situations where there are more results available than can be displayed on a single page. The page token overrides the other inputs. The other inputs will be ignored when the page token input is used.
results
The array of places or points of interest that match the search query, providing information such as place names, addresses, ratings, and other details for each result. Consists of a list of objects converted from the JSON response. It will always include places (one or more) if the request was successful (status = OK). When the request returns nothing, the results will be null, and the error will contain the value "ZERO_RESULTS".
next_page_token
A token provided in the API response that can be used to retrieve additional results beyond the initial set when there are more results available than can be displayed on a single page. It enables paginated access to search results.
info_messages
Informational messages or notifications provided by the API that may convey details about the search request or any additional notes or cautions related to the results.
error
An indication that an error has occurred during the API request, typically accompanied by an error code and message, providing information about what went wrong. See here for a list of possible errors: Google Maps Text Search API - Places Search Status.