Mapulus – Support: How to Use the Nearest Feature to Find a Location Nearby in Zapier

Mapulus Help Centre

Integrating Mapulus and Zapier for Proximity Searches

Discover how to easily find the nearest locations using Zapier and the Mapulus API.

Introduction

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.

Prerequisites:

  • A Zapier account. If you don’t have one, you can create one for free at www.zapier.com.
  • An active Mapulus account with an API key. Sign up for free at app.mapulus.com if you don’t have an account.

Step 1: Setting Up Your Mapulus Account

Before starting with Zapier, generate an API key in your Mapulus account. Refer to Connecting Zapier to Mapulus for guidance.

Step 2: Configuring the Zap in Zapier

Create a Zap in Zapier to use the Mapulus API for finding the nearest location.

Customer locations on a Mapulus map

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.

Step 3: Integrating Further Actions

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.

Customer locations on a Mapulus map

Customer locations on a Mapulus map

Conclusion

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.