Routing APIs
Blazing fast routing
Global coverage
The Maptoolkit Routing APIs offer robust functionality, including A to B routing, Map Matching, and isochrone calculations for various transportation modes (car, bike, and foot), with customizable weighting options.
Our Routing APIs are available with request-based pricing on the RapidAPI marketplace and as part of Maptoolkit Enterprise. For more details, see Maptoolkit Pricing.
You might also be interested in:
- Route Enhancement API
- Isochrone API
Example
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://static.maptoolkit.net/css/maplibre-gl.css" />
<style>
body { width: 100%; height: 100%; padding: 0; margin: 0; font-family: Arial, sans-serif; }
#map { width: 100%; height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mapbox-polyline/1.1.1/polyline.min.js"></script>
<script>
// Initialize MapLibreGL map
let map = new maplibregl.Map({
container: "map",
style: "https://static.maptoolkit.net/styles/toursprung/terrain.json?api_key=your_api_key",
center: [11.413507, 47.270537],
zoom: 13,
});
map.on("load", () => {
// Get route from Routing API
let start = [11.393712, 47.259938],
end = [11.430896, 47.28187];
let url = new URL("https://routing.maptoolkit.net/route");
url.searchParams.append("point", `${start[1]},${start[0]}`);
url.searchParams.append("point", `${end[1]},${end[0]}`);
url.searchParams.append("routeType", "car");
url.searchParams.append("api_key", "your_api_key");
fetch(url)
.then((r) => r.json())
.then((route) => {
let path = route.paths[0];
// Add route polyline to map
let coordinates = polyline.decode(path.points).map(c => c.reverse());
console.log(coordinates);
map.addLayer({
id: "route",
type: "line",
source: {
type: "geojson",
data: {
type: "Feature",
geometry: {
type: "LineString",
coordinates: coordinates,
},
},
},
layout: {
"line-join": "round",
"line-cap": "round",
},
paint: {
"line-color": "#2a3561",
"line-width": 5,
},
});
// Add instruction markers with popup to map
path.instructions.forEach((instruction) => {
let $img = document.createElement("img");
$img.src = "https://static.maptoolkit.net/sprites/toursprung/route-via.svg";
$img.width = 12;
$img.height = 12;
$img.style["cursor"] = "pointer";
new maplibregl.Marker({
element: $img,
anchor: "center",
})
.setLngLat(instruction.coordinate.reverse())
.addTo(map)
.setPopup(new maplibregl.Popup().setHTML(`<p>${instruction.text}</p>`));
});
// Add route end marker
let $img = document.createElement("img");
$img.src = "https://static.maptoolkit.net/sprites/toursprung/marker.svg";
$img.width = 29;
$img.height = 30;
let marker = new maplibregl.Marker({
element: $img,
anchor: "bottom",
})
.setLngLat(coordinates[coordinates.length - 1])
.addTo(map);
});
});
</script>
</body>
</html>
We're here to help.
My name is Peter Höflehner and I will be your project- and key account manager.