Get started
Get a key, lock it to your site or app, and put a map on your page in a few lines.
1. Get a key
An API key tells N-Ways which project a request comes from, so it can apply that project’s restrictions and quotas and count its usage. Keys belong to a project: one per app or customer is a good start, so each one’s usage and limits stay apart.
Keys come from the N-Ways partner console. Sign up with Google, Apple or email and get your key in a minute. Free usage every month.
- Sign in with your Google or Apple account or a work email.
- Name your company. That’s the only question: your organisation, a first project and a key are made at once, and they work straight away.
- Copy the key: the console shows it only once. Treat it like a password. The same screen has the three steps to put it in a website, an Android or iOS app, or your server.
Every API has free calls each month. Past them, add credit in the console’s Billing (PalmPay: checkout, or a transfer to your organisation’s own account number) and pay only for what you use; with no credit left, calls past the free ones get a 402 BILLING_DISABLED until you add some. More projects, keys and the APIs each may call are in Projects and keys.
2. Restrict it
A key in a web page or an app can be read by anyone. Restrictions make a copied key useless anywhere else. Give each key one kind of application restriction and only the APIs it needs:
| Where the key is used | Restrict it to | Example |
|---|---|---|
| A website | Its addresses (HTTP referrers) | https://shop.example.com/*, https://*.example.com/* |
| An Android app | Its package name and signing certificate’s SHA-1 | com.example.rider + DA:39:A3:… |
| An iOS app | Its bundle ID | com.example.rider |
| Your servers | Their public IP addresses | 203.0.113.7, 198.51.100.0/24 |
Then limit the key to the APIs that app calls: a web page that only shows a map needs Maps, not Routes. More on restrictions
Use a separate key for each website, app and server. A key for your servers, restricted by IP address, must never appear in a web page or app.
3. Show a map
Paste this into an HTML file and open it. It loads the N-Ways Maps SDK (MapLibre GL JS included) and shows Lagos.
<link rel="stylesheet" href="https://nways.ng/sdk/v1/maplibre-gl.css" />
<div id="map" style="height: 480px"></div>
<script type="module">
import { createMap } from 'https://nways.ng/sdk/v1/nways-maps.standalone.js'
createMap({ container: 'map', key: 'YOUR_API_KEY', center: [3.3792, 6.5244], zoom: 12 })
</script>Coordinates go longitude first, then latitude, as in GeoJSON: [3.3792, 6.5244] is central Lagos (Yaba). The Maps SDK guide covers dark maps, French labels, markers and drawing a route.
4. Find a place
Geocoding takes what people type, including NIPOST postcodes and GhanaPost GPS addresses:
curl "https://nways.ng/maps/v1/geocode?q=GA-183-8164" -H "X-NWays-Api-Key: YOUR_API_KEY"import { createClient } from 'https://nways.ng/sdk/v1/nways-maps.standalone.js'
const nways = createClient({ key: 'YOUR_API_KEY' })
const { results } = await nways.geocode('Allen Avenue, Ikeja', { near: { lat: 6.6, lng: 3.35 } })
console.log(results[0].name, results[0].location.coordinates) // [lng, lat]5. Get a route
Ask for a route between two points (or to a NIPOST postcode) and how you’re travelling:
curl -X POST "https://nways.ng/maps/v1/routes/compute" \
-H "X-NWays-Api-Key: YOUR_API_KEY" -H "Content-Type: application/json" \
-d '{"origin": {"lat": 6.6018, "lng": 3.3515}, "destination": {"lat": 6.4541, "lng": 3.3947}, "mode": "okada"}'const { routes } = await nways.route({
origin: { lat: 6.6018, lng: 3.3515 },
destination: { lat: 6.4541, lng: 3.3947 },
mode: 'okada',
})
console.log(Math.round(routes[0].durationS / 60), 'min,', (routes[0].distanceM / 1000).toFixed(1), 'km')The Routes guide covers kekes, danfos, boats, tolls, stops and fares.