Findort in action.
Typical places where people enter addresses, from the ready-made field to your own list and map. Everything runs live against the Findort API, just start typing.
Shop checkout
The customer types street and number, Findort fills in postcode, city and country. Fewer typos, fewer parcels coming back.
<findort-search key="pk_…" types="address"
country="ch"></findort-search>
<script>
document.querySelector('findort-search')
.addEventListener('findort-select', (e) => {
const a = e.detail.place.address;
form.street.value = a.street;
form.zip.value = a.postcode;
form.city.value = a.city;
});
</script>Delivery zone check
A pizza courier in Bern Wankdorf delivers up to 8 km as the crow flies. Findort returns the coordinates, the straight-line distance is one line of maths. Findort does not compute driving routes.
el.addEventListener('findort-select', (e) => {
const { lat, lon } = e.detail.place.location;
const km = airDistance(shop, { lat, lon });
show(km <= 8 ? 'We deliver' : 'Too far');
});Store finder
Enter an address, see the nearest store. With near, Findort ranks results close by higher, the browser computes the straight-line distance.
const places = await findort.search(q, { near: [46.95, 7.44] });
stores.sort((a, b) => airDistance(a, place) - airDistance(b, place));Pick an address above to see the stores by distance.
- Bike workshop BernAarbergergasse 40, 3011 Bern
- Bike workshop ZürichLangstrasse 120, 8004 Zürich
- Bike workshop BaselClarastrasse 2, 4058 Basel
- Bike workshop LucerneHirschmattstrasse 30, 6003 Luzern
- Bike workshop LausanneRue de Bourg 8, 1003 Lausanne
Your own result list
The ready-made field is not enough? With autocomplete() from the JavaScript library you build the list yourself: an icon per type, the match highlighted, the distance to you, grouped into addresses, places and shops. It searches only after a short pause in typing and from three characters on, which saves requests.
import { Findort, autocomplete } from 'findort';
const findort = new Findort('pk_…', { country: 'ch' });
const suggest = autocomplete(findort, { wait: 200, minLength: 3 });
input.addEventListener('input', async () => {
const q = input.value;
const places = await suggest(q, { limit: 8, near: here });
list.replaceChildren(...places.map((p) => {
const li = document.createElement('li');
li.className = `hit hit-${p.type}`; // icon per type with CSS
li.append(
highlight(p.name, q), // <mark> around the match
line(p.address.postcode, p.address.city),
badge(km(here, p.location)), // as the crow flies
);
li.onclick = () => choose(p);
return li;
}));
});
// Your own list: show the attribution yourself
footer.textContent = '© OpenStreetMap';Results appear from three characters on.
Results on a map
Every result as a numbered pin, with the list beside it: hover an entry and its pin stands out, and the other way round. Once you have zoomed in, Findort prefers results near the centre of the map (near). Move the map and, if you like, search only inside the visible area (bbox). The map is Leaflet with swisstopo tiles, any other map library works the same way.
import L from 'leaflet';
import { Findort, autocomplete } from 'findort';
const map = L.map('map').setView([46.8, 8.2], 8);
L.tileLayer(tiles, { attribution: '© swisstopo' }).addTo(map);
const pins = L.featureGroup().addTo(map);
const findort = new Findort('pk_…', { country: 'ch' });
const suggest = autocomplete(findort, { wait: 200, minLength: 3 });
input.addEventListener('input', async () => {
const c = map.getCenter();
const places = await suggest(input.value, {
limit: 10,
near: [c.lat, c.lng], // prefer the map centre
// only inside the view: bbox: map.getBounds().toBBoxString()
});
pins.clearLayers();
places.forEach((p, i) => {
L.marker([p.location.lat, p.location.lon], {
icon: L.divIcon({
className: `pin pin-${p.type}`, // colour per type
html: `${i + 1}`, // number as in the list
}),
})
.bindTooltip(text(p.label)) // text, not HTML
.on('click', () => choose(p))
.addTo(pins);
});
if (places.length) map.fitBounds(pins.getBounds(), { maxZoom: 16 });
});Type something, the results appear as pins.
Location to address
For apps and forms with "Use my location": coordinates become an address with a house number.
const res = await fetch(
'https://api.findort.ch/v1/reverse?lat=46.9466&lon=7.4441&key=pk_…');
const { results } = await res.json();
console.log(results[0].label); // Bundesplatz 3, 3011 Bernor an example:
Build it into your form.
50,000 requests a month are free.