Google Maps API for reverse geo location
3 minute read Intermediate
How to use reverse geo location
Use this integration to simplify getting the geographic information of users
How it works
Users have to share the location pin. The location pin provides latitude and longitude information of the user. This can be used to get the following information from Google Maps API.
- Country
- State
- District or City or Village
- Ward name (if present)
- Pincode
- Address
Once the information is returned from the api response, it can be added to the contact field of the user.
How to use in the flow
-
Sample flow to try out the feature.
-
Use the location interactive message to get the location of the user
-
In call a webhook node, select
function
and entergeolocation
- Go to
Function body
and pass the following parameters
{ "lat": "@results.result_1.latitude", "long": "@results.result_1.longitude" }
Here the result_1
is the result storing the location pin shared by the user
-
Following parameters are the response
{ "ward": "", "success": true, "state": "", "postal_code": "", "district": "", "country": "", "city": "", "address": "" }
-
Use the following @results format to access the response of the api
- to access country - @results.loc.country
- to access state - @results.loc.state
- to access ward - @results.loc.ward
- to access district - @results.loc.district
- to access city/village/locality - @results.loc.city
- to access postal code - @results.loc.postal_code
- to access the address - @results.loc.address
Here loc
is the variable name which is the storing the result of webhook call.
- Any one or multiple of these parameters can be used to confirm the actual location of the user. The geographical information returned is as per the Google Maps Reverse Geo Locate API. The levels correspond to the the administrative_area_levels available in Google Maps.
Webhook response vs the google maps api
- Country corresponds to address_components[“country”]
- State corresponds to address_components[“administrative_area_level_1”]
- District corresponds to address_components[“administrative_area_level_2”]
- City corresponds to address_components[“locality”]
- Ward corresponds to address_components[“administrative_area_level_3”]
- Postal_code corresponds to address_components[“postal_code”]
- Address corresponds to formatted_address
As subsequent steps, organization can get the user to confirm if the location picked up is correct If the information is correct, the contact variables can be updated and/or users can be clubbed into geographical collections for targeting at a later point.