Discover how to easily find the nearest locations using Zapier and the Mapulus API.
The Mapulus API offers a powerful feature for finding locations nearby a specified latitude/longitude or address. This guide will show you how to leverage this capability in Zapier, enabling automated location searches and integrations with other services.
Before starting with Zapier, generate an API key in your Mapulus account. Refer to Connecting Zapier to Mapulus for guidance.
Create a Zap in Zapier to use the Mapulus API for finding the nearest location.
Use the following script in a Javascript Code step in Zapier:
const myHeaders = { "Content-Type": "application/json", "Authorization": "Bearer <bearer-token>" // Replace with your API token }; const queryParams = new URLSearchParams({ "layer_id": "<layer-id>", // Replace with your desired layer ID "nearest[lat]": "latitude", "nearest[lon]": "longitude", "nearest[address]": "38 example st, NY, USA", // Use either a lat/lon or address. Exclude the one you don't need. "nearest[sort_by]": "time", // Can be 'time' or 'distance' "nearest[profile]": "driving", "nearest[limit]": "10" // Up to 24 locations }).toString(); const url = `https://api.mapulus.com/api/v1/locations?${queryParams}`; const requestOptions = { method: 'GET', headers: myHeaders }; const perform = async (z, bundle) => { const res = await z.request({ url: url, method: requestOptions.method, headers: requestOptions.headers }); const responseJson = await res.json; const closestLocation = responseJson.data[0]; if (closestLocation.nearest_meta.seconds_from_source > 30000) { // 30 secs. Adjust time threshold as needed return { closest: null, found: false }; } return { closest: closestLocation, found: true }; };
Replace <bearer-token> and <layer-id> with your actual Mapulus API token and layer ID, respectively. Update the latitude and longitude values accordingly.
<bearer-token>
<layer-id>
After finding the location, you can set up additional steps, like sending an email alert using the Zapier email step. Use a filter step to exit the zap if no location is found.
With these steps, you can automate location searches in your Mapulus account using Zapier. This integration enhances your ability to manage location data efficiently and in real-time.
For further assistance, feel free to contact our support team.