By: Amy Ghate
With our geofencing toolkit, track where your assets are in relation to country, state, county, census block, zip code, or statistical boundaries. Logistics operations can now monitor when their assets move across customized boundaries, pulled from our global boundary dataset — everything from provinces in Canada to administrative districts in Beijing.
If you’re building a logistics dashboard for a fleet of delivery vehicles operating across Southern California, for example, it’s easy to set up a geofence and build out a simple set of rules to help you track each vehicle. Each time one of your assets reports its location, you’ll receive structured metadata about where your asset is. Use that metadata to write custom rules and take action if rules break.
Let’s jump into the code — if your vehicle is in Los Angeles County at longitude 35.0551562 and latitude -118.1751554, ask for metadata about this location with a request like this:
https://api.mapbox.com/v4/mapbox.enterprise-boundaries-a2-v1/tilequery/-118.1550191,34.6534237.json?access_token=your_token_here
Then, you’ll receive metadata like this, which confirms the vehicle is still in Los Angeles:
{
"name": "Los Angeles",
"parent_0": "US",
"parent_1": "USA106",
"level": "a2",
"parent_2": "",
"name_ascii": "",
"parent_4": "",
"parent_3": "",
"bounds": [-118.945, 33.705, -117.646, 34.823],
"z_min": 2,
"country_code": "US"
}
If you receive a ping that the vehicle has moved to longitude -118.1751554 and latitude 35.0551562 , request metadata through a query like:
https://api.mapbox.com/v4/mapbox.enterprise-boundaries-a2-v1/tilequery/-118.1751554,35.0551562.json?access_token=your_token_here
And you’ll receive metadata similar to the one below, which indicates that the vehicle has moved to Kern County:
{
"name": "Kern",
"parent_0": "US",
"parent_1": "USA106",
"level": "a2",
"parent_2": "",
"name_ascii": "",
"parent_4": "",
"parent_3": "",
"bounds": [-120.194, 34.791, -117.616, 35.798],
"z_min": 2,
"country_code": "US"
}
Now that the county name is Kern, your application will recognize that a geofence has been broken and can take further action, like using Twilio to call or SMS message your driver.
Interested in using Mapbox to enhance your asset tracking and geofencing? Contact our sales team and mention this blog post.
Enhance geofencing with global boundary data was originally published in Points of interest on Medium, where people are continuing the conversation by highlighting and responding to this story.