0

Returns the nearest named location for a given GPS coordinates.

by
Published Oct 17, 2025

## Search for nearest place by coordinates You can use this endpoint to find the nearest place from given coordinates. *Note: If you specify coordinates of a secluded place (e.g. middle of the ocean), the nearest point can be very far from the coordinates.*

Script meteosource Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Returns the nearest named location for a given GPS coordinates.
4
 * ## Search for nearest place by coordinates
5

6
You can use this endpoint to find the nearest place from given coordinates.
7

8
*Note: If you specify coordinates of a secluded place (e.g. middle of the ocean), the nearest point can be very far from the coordinates.*
9
 */
10
export async function main(
11
	auth: RT.Meteosource,
12
	lat: string | undefined,
13
	lon: string | undefined,
14
	language?: 'cs' | 'en' | 'de' | 'es' | 'fr' | 'pl' | 'pt' | undefined,
15
	key?: string | undefined
16
) {
17
	const url = new URL(`https://www.meteosource.com/api/v1/${auth.tier}/nearest_place`)
18
	for (const [k, v] of [
19
		['lat', lat],
20
		['lon', lon],
21
		['language', language],
22
		['key', key]
23
	]) {
24
		if (v !== undefined && v !== '') {
25
			url.searchParams.append(k, v)
26
		}
27
	}
28
	const response = await fetch(url, {
29
		method: 'GET',
30
		headers: {
31
			'X-API-Key': auth.apiKey
32
		},
33
		body: undefined
34
	})
35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39
	return await response.json()
40
}
41