How to Set Up Mapbox API Keys Integration for Your MapCosmos Widgets
MapCosmos uses two different Mapbox API keys to keep your site secure and running smoothly. The public key shows the map on your website, while the secret key handles server-side tasks like geolocation.
This guide will show you how to create both keys and connect them to your MapCosmos account.
Step 1: Create Your Public API Key (for your website)
Use this key to display the MapCosmos widget on your website. For security, make sure it only works on your domain.
- Navigate to Mapbox: Go to your Mapbox account page and sign in.
- Create a Token: In the Tokens section, click the Create a token button.
- Name Your Token: Give your token a descriptive name, such as "MapCosmos Public Key".
- Restrict the URL: This step is important. In the URLs section, enter the domain where your map will appear (for example, yourstore.com).
- Confirm: Click the Create token button to save the newly generated key.
Step 2: Create Your Secret API Key (for geolocation)
MapCosmos uses this key behind the scenes for server-side processes. Do not add any domain restrictions to it.
- Create Another Token: Back in your Mapbox dashboard, click Create a token again.
- Name Your Token: Give it a name, like "MapCosmos Secret Key".
- Do Not Add Restrictions: Leave the URLs section blank for this key. If you add a URL restriction, geolocation services will not work correctly.
- Click Create token.
Step 3: Add Both Keys to MapCosmos
Next, add both keys to your MapCosmos settings.
- Log in to your MapCosmos account and navigate to General Settings.
- Paste your first key (the public one with URL restrictions) into the API key (public) field.
- Paste your second key (the secret one with no restrictions) into the API key (secret) field.
- In the Map Provider section, under MapBox:
- Click Save changes.
✅ You’re All Set!
Your store locator is now set up to use Mapbox securely. Your users will enjoy a fast and modern experience. If you have any questions, feel free to contact our support team at contact@mapcosmos.com.
Need Help Choosing a Map Provider?
If you’re still choosing a map provider, check out our article that compares the pros and cons of Google Maps and Mapbox for business use.
‍