GetTerritories(lat, long)
returns territories array for any given lat
and long
coordinates.
Input
lat
: latitude
long
: longitude
Output
A JSON array of territories, consisting of territory group name, territory group code, territory name, and territory code.
Example
Let's say you created the "North-East" territory:
In this scenario, if we call GetTerritories('40.607925', '-76.218295') it would return:
[{"groupCode":"sales-team","territoryCode":"north-east","groupName":"Sales Team","territoryName":"North-East"}]
If you provide coordinates outside of this or any other territory, the GetTerritories()
function would return an empty array.
Fetching territories via API
You can use the GetTerritories()
function to fetch your Mapsly territories via API using a custom endpoint. To accomplish that, you need to create a button, check the "Expose as API endpoint," and provide some name to your endpoint:
In the actions of your button add a code statement where you will provide lat
and long
from your request, for example:
{{ GetTerritories(request.parameters.lat, request.parameters.long) }}
For example, your GET request might look like this:
https://api.mapsly.com/v1/a/105/button/run/territories?async=0&apikey=YOUR_API_KEY&lat=40.607925&long=-76.218295
If you only have an address, but no coordinates
You may also pass the address as a URL parameter and retrieve territories. To accomplish that, you will need to use the Geocode()
function inside your button and then pass the geocoded coordinates to your GetTerritories()
function as input:
See also: