Create client credentials
Go to the Admin dashboard to create client credentials for each environment, such as development, staging, and production. Store the client ID and client secret in your environment variables.
Create client credentialsGet client credentials, install MapLibre GL JS, and render your first GrabMaps map in minutes.
Go to the Admin dashboard to create client credentials for each environment, such as development, staging, and production. Store the client ID and client secret in your environment variables.
Create client credentialsInstall MapLibre GL JS so your app can load Grab map styles and render interactive maps.
View map setupLoad a Grab map style, choose a starting location, and add controls such as zoom, navigation, and attribution.
Initialize a mapInstall the package, then fetch the map style before creating the map:
npm install maplibre-glimport maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';Request an access token on your server, then use it as a Bearer token when loading protected APIs.
Use MapLibre GL JS to render GrabMaps tiles.
Open the demo page to verify your access token, tiles, and attribution are working correctly.
import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
// Obtain an access token from your server before loading the map.
const accessToken = '<ACCESS_TOKEN>';
fetch('https://api.maps.grab.com/api/v1/styles/urban-light-partner/descriptor', {
headers: {
'Authorization': `Bearer ${accessToken}`
}
})
.then(response => {
if (!response.ok) {
throw new Error('Request failed with HTTP ' + response.status);
}
return response.json();
})
.then(style => {
const map = new maplibregl.Map({
container: 'map',
style: style,
center: [103.8198, 1.3521],
zoom: 12,
transformRequest: (url) => {
const resourceUrl = new URL(url, window.location.href);
return resourceUrl.origin === 'https://api.maps.grab.com'
? { url, headers: { Authorization: `Bearer ${accessToken}` } }
: { url };
},
});
map.addControl(new maplibregl.NavigationControl(), 'top-right');
});Create your first interactive map with a Grab style and MapLibre GL JS.
See guideAdd keyword search, nearby place discovery, and reverse geocoding.
See guideShow routes between locations and help users navigate.
See guideCustomize map styles, controls, layers, attribution, and interactions.
See guideUse this endpoint to load the map style used by MapLibre GL JS.
/api/v1/styles/{Style}/descriptorReturns the selected named map style JSON. Use urban-light-partner as the default style.
// Obtain an access token from your server before loading the map.
const accessToken = '<ACCESS_TOKEN>';
fetch('https://api.maps.grab.com/api/v1/styles/urban-light-partner/descriptor', {
headers: {
'Authorization': `Bearer ${accessToken}`
}
})
.then(response => {
if (!response.ok) {
throw new Error('Request failed with HTTP ' + response.status);
}
return response.json();
})
.then(style => {
const map = new maplibregl.Map({
container: 'map',
style: style,
center: [103.8198, 1.3521],
zoom: 12,
transformRequest: (url) => {
const resourceUrl = new URL(url, window.location.href);
return resourceUrl.origin === 'https://api.maps.grab.com'
? { url, headers: { Authorization: `Bearer ${accessToken}` } }
: { url };
},
});
map.addControl(new maplibregl.NavigationControl(), 'top-right');
});