Till innehållet
kart-api.se

Which municipality is a coordinate in?

curl 'https://api.kart-api.se/v1/kommun/lookup?lat=58.705&lon=15.77'
{"kommunkod":"0562","kommunnamn":"Finspång","lanskod":"05","lansnamn":"Östergötland",
 "attribution":["©Lantmäteriet · Administrativ indelning · CC BY 4.0"]}

The lookup is point-in-polygon against Lantmäteriet's boundaries — not nearest town, not a bounding box. A point in the archipelago lands in the right municipality even when the nearest locality is in the neighbouring one.

Outside Sweden

404 with a reason. We would rather say "outside Sweden's municipalities" than guess at the nearest one.

The boundary as geometry

curl 'https://api.kart-api.se/v1/kommun/0562'          # GeoJSON Feature
curl 'https://api.kart-api.se/v1/kommun/0562/grannar'  # neighbours

The neighbour lookup counts both a shared border and 200 metres across water, so archipelago and bay neighbours are included. That sounds pedantic until you build a regional view and notice the municipality across the strait is missing.

The municipality code

Four digits, leading zero included: Finspång is 0562, not 562. Drop the zero and you land in a different municipality or none at all — the most common mistake we see in our own logs.