To provide enhanced security and performance, MapCosmos uses two separate Mapbox API keys: a public key for displaying the map on your website, and a secret key for server-side functions like geolocation.
This guide provides the steps for generating both keys and integrating them with your MapCosmos account.
Step 1: Create Your Public API Key (for your website)
This key is used to display the MapCosmos widget on your website. It must be restricted to your domain for security.
- 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 is a crucial step. Under the URLs section, you must enter the domain of the website where you will display your map (e.g., yourstore.com).
- Confirm: Click the Create token button to save the newly generated key.
Step 2: Create Your Secret API Key (for geolocation)
This key is used internally by MapCosmos for server-side processes. It must not have any domain restrictions.
- 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 completely blank for this key. Adding a URL restriction will cause errors with geolocation services.
- Click Create token.
Step 3: Add Both Keys to MapCosmos
Now you will add the two 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 securely configured to use Mapbox, providing a fast and stylish experience for your users. If you have any questions, please don't hesitate to contact our support team at contact@mapcosmos.com.
Need Help Choosing a Map Provider?
If you're still deciding between map providers, we've written a detailed article comparing the pros and cons of Google Maps and Mapbox for business use.