Common Errors & Troubleshooting
Quick solutions to the most common issues when using MapMetrics Atlas API.
🔴 Map Not Loading (Blank Screen)
Symptoms:
- Map container shows blank/white screen
- Console error:
Failed to load map styleor401 Unauthorized - Browser developer tools show 401 errors
Cause:
Missing or invalid API token (99% of cases)
Solution:
Step 1: Check if you have a token
// ❌ WRONG - Placeholder not replaced
style: 'YOUR_STYLE_URL_WITH_TOKEN'
// ✅ CORRECT - Actual URL from portal
style: 'https://gateway.mapmetrics-atlas.net/styles/?fileName=abc-123/style.json&token=eyJhbG...'Step 2: Get your API token
- Visit MapMetrics Portal
- Sign up (free)
- Copy your complete style URL
- Paste it in your code
Step 3: Verify the token is in the URL Your style URL should include &token= parameter at the end.
🔴 Error: 401 Unauthorized
For Map Loading:
Error Message:
GET https://gateway.mapmetrics-atlas.net/styles/... 401 (Unauthorized)Cause: Invalid or missing token in style URL
Solution:
// Make sure your style URL includes the token
const map = new mapmetricsgl.Map({
container: 'map',
style: 'https://gateway.mapmetrics-atlas.net/styles/?fileName=YOUR_ID/style.json&token=YOUR_TOKEN',
center: [lng, lat],
zoom: 12
});For REST API Calls:
Error Message:
{
"error": "401 Token required"
}Cause: Missing token query parameter
Solution:
// ❌ WRONG - No token
fetch('https://gateway.mapmetrics-atlas.net/directions/', {
method: 'POST',
body: JSON.stringify({...})
});
// ✅ CORRECT - Token in query parameter
fetch('https://gateway.mapmetrics-atlas.net/directions/?token=YOUR_TOKEN', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({...})
});🔴 Map Container Has No Height
Symptoms:
- Map container exists but has 0px height
- Can't see the map
Cause:
Missing CSS height on map container
Solution:
Add CSS:
<style>
#map {
height: 500px; /* or 100vh for full screen */
width: 100%;
}
</style>Or inline:
<div id="map" style="height: 500px; width: 100%;"></div>🔴 React: Map Renders Multiple Times
Symptoms:
- Multiple map instances created
- Memory leaks
- Map behaves strangely
Cause:
Not properly managing map lifecycle in React
Solution:
import { useEffect, useRef } from 'react';
import mapmetricsgl from '@mapmetrics/mapmetrics-gl';
function MapComponent() {
const mapContainerRef = useRef(null);
const mapRef = useRef(null); // ✅ Store map instance
useEffect(() => {
// ✅ Check if map already exists
if (mapRef.current) return;
const map = new mapmetricsgl.Map({
container: mapContainerRef.current,
style: 'YOUR_STYLE_URL',
center: [lng, lat],
zoom: 12
});
mapRef.current = map;
// ✅ Cleanup on unmount
return () => {
map.remove();
mapRef.current = null;
};
}, []); // ✅ Empty dependency array
return <div ref={mapContainerRef} style={{ height: '500px' }} />;
}🔴 Coordinates Not Displaying Correctly
Symptoms:
- Marker appears in wrong location
- Map centered on wrong place
Cause:
Mixing up longitude and latitude order
Solution:
MapMetrics uses [longitude, latitude] order:
// ❌ WRONG - [latitude, longitude]
center: [40.7128, -74.0060] // This is backwards!
// ✅ CORRECT - [longitude, latitude]
center: [-74.0060, 40.7128] // Longitude first!
// ✅ For API requests, use object notation:
{
"lat": 40.7128,
"lon": -74.0060
}Remember:
- Map/SDK:
[longitude, latitude](array) - REST API:
{lat: number, lon: number}(object)
🔴 Geocoding Returns Empty Results
Symptoms:
- API returns
[]or no features - Can't find addresses
Common Causes:
1. Missing Token
// ❌ WRONG
fetch('https://gateway.mapmetrics-atlas.net/forward-geocode/?text=Paris')
// ✅ CORRECT
fetch('https://gateway.mapmetrics-atlas.net/forward-geocode/?token=YOUR_TOKEN&text=Paris')2. Text Not URL Encoded
// ❌ WRONG - Spaces not encoded
const url = `...?text=New York City`
// ✅ CORRECT - Use encodeURIComponent
const text = encodeURIComponent('New York City');
const url = `...?text=${text}`3. Too Specific Query
// ❌ Might not find
"1234 Some Random Street That Doesn't Exist"
// ✅ Better - Start broad
"Paris, France"
"New York"🔴 CORS Errors
Symptoms:
Access to fetch at '...' from origin 'http://localhost' has been blocked by CORS policyCause:
Browser security - usually only in development
Solution:
For Development: Use a local server, not file://
# Use any local server
python -m http.server 8000
# or
npx serve .
# or
npm run devFor Production: Deploy to a proper domain (Vercel, Netlify, etc.)
🔴 NPM Package Import Errors
Symptoms:
Module not found: Can't resolve '@mapmetrics/mapmetrics-gl'Solution:
1. Install the CORRECT package:
# ✅ CORRECT - MapMetrics package
npm install @mapmetrics/mapmetrics-gl
# ❌ WRONG - This is MapLibre, NOT MapMetrics!
npm install maplibre-gl2. Import correctly:
// ✅ CORRECT
import mapmetricsgl from '@mapmetrics/mapmetrics-gl';
import '@mapmetrics/mapmetrics-gl/dist/mapmetrics-gl.css';
// ❌ WRONG
import maplibregl from 'maplibre-gl'; // Wrong package!3. If using TypeScript, you may need:
declare module '@mapmetrics/mapmetrics-gl';🔴 Using Wrong Package (maplibre-gl vs @mapmetrics/mapmetrics-gl)
Symptoms:
- Map doesn't load even with valid token
- Authentication errors with MapMetrics style URLs
- Missing MapMetrics-specific features
Cause:
Using maplibre-gl (the base library) instead of @mapmetrics/mapmetrics-gl (MapMetrics custom fork)
Solution:
Uninstall wrong package and install correct one:
# Remove wrong package
npm uninstall maplibre-gl
# Install correct package
npm install @mapmetrics/mapmetrics-glUpdate imports:
// ❌ Before (WRONG)
import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
// ✅ After (CORRECT)
import mapmetricsgl from '@mapmetrics/mapmetrics-gl';
import '@mapmetrics/mapmetrics-gl/dist/mapmetrics-gl.css';Update all references:
// ❌ WRONG
const map = new maplibregl.Map({...});
const marker = new maplibregl.Marker();
// ✅ CORRECT
const map = new mapmetricsgl.Map({...});
const marker = new mapmetricsgl.Marker();Why this matters:
- MapMetrics GL is a custom fork of MapLibre with proprietary features
- MapMetrics style URLs only work with the MapMetrics package
- The packages are NOT interchangeable
🔴 Directions API: No Route Found
Symptoms:
{
"error": "No route found"
}Common Causes:
1. Unreachable Locations
// Locations on different continents with no ferry routes
locations: [
{ lat: 40.7128, lon: -74.0060 }, // New York
{ lat: 51.5074, lon: -0.1278 } // London - needs ferry!
]2. Invalid Costing Model
// ❌ Wrong costing for the route
costing: "bicycle" // But route includes highways
// ✅ Use appropriate costing
costing: "auto"3. Coordinates Reversed
// ❌ WRONG - lat/lon format in REST API
locations: [
{ lon: -74.0060, lat: 40.7128 } // Backwards!
]
// ✅ CORRECT - lat comes first in objects
locations: [
{ lat: 40.7128, lon: -74.0060 }
]🆘 Still Having Issues?
Checklist:
- [ ] Do you have a valid token? Get one at portal.mapmetrics.org
- [ ] Is the token in the URL? Check for
?token=or&token= - [ ] Is your map container styled? Add
height: 500pxto CSS - [ ] Are coordinates in correct order?
[longitude, latitude]for maps - [ ] Check browser console for error messages
- [ ] Is JavaScript loading? Check Network tab in DevTools
- [ ] Using HTTPS in production? Some features require secure context
Get Help:
- 📖 Documentation
- 💬 Discord Community
- 📧 Support: Contact via portal
🎓 Prevention Tips
Before You Start:
- ✅ Sign up at portal.mapmetrics.org
- ✅ Get your style URL (includes token)
- ✅ Test with simple example first
- ✅ Check browser console for errors
- ✅ Read relevant example docs
While Developing:
- ✅ Always check token is present
- ✅ Use browser DevTools to debug
- ✅ Test API calls with curl first
- ✅ Verify coordinates are correct
- ✅ Keep documentation handy
Most issues are solved by:
- Getting a valid API token
- Adding it to your requests
- Setting proper container height
99% of "map not loading" issues = missing/invalid token! 🔑