N-Ways
Developer docsAutocomplete

Autocomplete

Suggestions while people type: streets, landmarks, businesses, NIPOST and GhanaPost codes, nearest first.

On this page

Suggestions as people type an address: streets, businesses, landmarks, areas, NIPOST postcodes and GhanaPost GPS codes, nearest first. Built for delivery address boxes and pickup search.

In a web page, the Maps SDK’s search box does it all: suggestions, keyboard, screen readers and sessions.

JavaScript
import { attachAutocomplete } from 'https://nways.ng/sdk/v1/nways-maps.standalone.js'

attachAutocomplete(document.querySelector('#address'), {
  key: 'YOUR_API_KEY',
  near: { lat: 6.5244, lng: 3.3792 },
  country: 'NG',
  onSelect: (place) => console.log(place.name, place.location.coordinates),
})

The API

cURL
curl "https://nways.ng/maps/v1/autocomplete?q=allen%20av&near=6.60,3.35&session=4f1c2a9e-7d3b-4e55-9a51-0c8e2b7f6d10&key=YOUR_API_KEY"
ParameterDescription
qRequired. What has been typed so far.
sessionThe search’s session token: 8 to 64 letters, digits, - or _ (a UUID is fine). The same on every request until the person picks a suggestion.
nearlat,lng: rank suggestions near this point (the person, or the map’s centre).
countryNG, GH, BJ, TG, GA, CI, LR, GN, SL, GW, SN, CM, BF, CV, or several, comma-separated.
typesOnly some kinds: address, street, business, place, area, postcode, ghanapost.
limitUp to 10 suggestions; 5 by default.
langen or fr.

The answer has results, in the same shape as Geocoding’s: name, formattedAddress, location and, where there is one, the postcode or ghanaPost code. Reference

Sessions and billing

A person typing “Allen Avenue” sends a dozen requests. With a session token, they’re one session: the first request is billed, the rest of the session isn’t. Start a new token after each pick (or when the box is cleared). Without a token, every request is billed as a session of its own. The answer’s X-NWays-Session-Billed header says whether this request was the billed one.

Tip:

Wait about 200 milliseconds after the last key before asking, and don’t ask for one or two letters: fewer requests, and the suggestions are better.