Endpoints

Alle sechs HTTP-Endpunkte mit Parametern, Code-Beispielen und Antwort-Schema. Wechsle die Tabs, um zwischen den Endpoints zu springen.

📍 Reverse-Geocoding GET /api/lookup.phpIm Playground testen ↗

Liefert den nächstgelegenen Ort zu einer Koordinate. Modus city bevorzugt bewohnte Städte (PPLC/PPLA), exact den nächsten Punkt überhaupt.

Parameter

NameTypDefaultBeschreibung
latPflichtfloatBreitengrad (-90 … 90).
lonPflichtfloatLängengrad (-180 … 180).
modestringcitycity = Städte-Präferenz (Astrologie, Wetter); exact = strikt nächster Ort.
extendedstringSiehe extended-Blöcke.
flag1Convenience für extended=…,flag.
langstringISO-Sprachcode für lokalisierte Namen.
keystringOptionaler API-Key.

Code-Beispiele

curl -s 'https://geoapi.world/api/lookup.php?lat=48.137&lon=11.575&mode=city&lang=de'
<?php
$url  = "https://geoapi.world/api/lookup.php?" . http_build_query([
    "lat"  => 48.137,
    "lon"  => 11.575,
    "mode" => "city",
    "lang" => "de",
]);
$data = json_decode(file_get_contents($url), true);

if ($data["hit"]) {
    echo "Ort: "      . $data["hit"]["name"]         . "\n";
    echo "Land: "     . $data["hit"]["country_code"] . "\n";
    echo "Zeitzone: " . $data["hit"]["timezone"]     . "\n";
    echo "Distanz: "  . $data["hit"]["distance_km"]  . " km\n";
}
const url = "https://geoapi.world/api/lookup.php?" + new URLSearchParams({
  lat: 48.137, lon: 11.575, mode: "city", lang: "de"
});
const res  = await fetch(url);
const data = await res.json();

if (data.hit) {
  console.log("Ort:", data.hit.name);
  console.log("Land:", data.hit.country_code);
  console.log("Zeitzone:", data.hit.timezone);
  console.log("Distanz:", data.hit.distance_km, "km");
}
import requests

resp = requests.get("https://geoapi.world/api/lookup.php", params={
    "lat":  48.137,
    "lon":  11.575,
    "mode": "city",
    "lang": "de",
})
data = resp.json()

if data["hit"]:
    h = data["hit"]
    print(f"Ort: {h['name']}")
    print(f"Land: {h['country_code']}")
    print(f"Zeitzone: {h['timezone']}")
    print(f"Distanz: {h['distance_km']} km")

data.hit ist null, wenn im Such-Radius nichts gefunden wurde. Mit mode=exact bekommst du auch Stadtteile/Quartiere statt der nächstgelegenen Stadt.

Antwort-Schema

Das hit-Objekt entspricht dem Place-Schema, plus distance_km (Entfernung der Eingabekoordinaten zum Ortsmittelpunkt).

📍 Länder GET /api/countries.php · /api/country.phpIm Playground testen ↗

Schlanke Länder-Liste für Country-Picker oder vollständiges Detail zu einem bestimmten Land.

Alle Länder — /api/countries.php

Liefert alle 252 Länder als schlanke Liste, sortiert nach Name.

NameBeschreibung
langISO-Sprachcode für lokalisierten Landesnamen.
flag1 = ergänzt flag_url pro Land.
curl -s 'https://geoapi.world/api/countries.php?lang=de&flag=1'
<?php
$json = file_get_contents("https://geoapi.world/api/countries.php?lang=de&flag=1");
$data = json_decode($json, true);

// Country-Picker im HTML rendern
echo '<select name="country">';
foreach ($data["results"] as $c) {
    printf('<option value="%s">%s</option>', $c["iso2"], htmlspecialchars($c["name"]));
}
echo '</select>';
const r = await fetch("https://geoapi.world/api/countries.php?lang=de&flag=1");
const d = await r.json();

const select = document.createElement("select");
d.results.forEach(c => {
  const opt = new Option(c.name, c.iso2);
  // Optional: Flag als Bild im optgroup-Label
  select.appendChild(opt);
});
import requests

r = requests.get("https://geoapi.world/api/countries.php",
                 params={"lang": "de", "flag": 1})
data = r.json()

# iso2 → Name, mit Flag-URL
for c in data["results"]:
    print(c["iso2"], c["name"], c.get("flag_url"))

Antwort-Felder pro Land: iso2, iso3, name, continent, currency_code, flag_url (letzteres nur bei flag=1).

Ein bestimmtes Land — /api/country.php?code=DE

Vollständige Country-Daten (Currency, Phone-Prefix, Postal-Format, Languages, Neighbours, Geonameid …) und optional die Liste aller Bundesländer.

NameBeschreibung
codePflichtISO-2-Code (DE, at, CH).
langISO-Sprachcode.
flag1 = ergänzt flag_url.
admin11 = ergänzt das Feld admin1[] mit allen Bundesländern/Kantonen/Provinzen.
curl -s 'https://geoapi.world/api/country.php?code=DE&lang=de&admin1=1&flag=1'
<?php
$url  = "https://geoapi.world/api/country.php?" . http_build_query([
    "code" => "DE", "lang" => "de", "admin1" => 1, "flag" => 1,
]);
$data = json_decode(file_get_contents($url), true);

$c = $data["country"];
echo "Land:        " . $c["name"]          . "\n";
echo "Hauptstadt:  " . $c["capital"]       . "\n";
echo "Währung:     " . $c["currency_code"] . " (" . $c["currency_name"] . ")\n";
echo "Telefon:    +"  . $c["phone_prefix"] . "\n";

foreach ($c["admin1"] as $r) {
    echo "  - " . $r["name"] . "\n";
}
const url = "https://geoapi.world/api/country.php?" + new URLSearchParams({
  code: "DE", lang: "de", admin1: "1", flag: "1"
});
const data = await (await fetch(url)).json();

const c = data.country;
console.log("Land:", c.name);
console.log("Hauptstadt:", c.capital);
console.log("Währung:", c.currency_code, "(" + c.currency_name + ")");
c.admin1.forEach(r => console.log("  -", r.name));
import requests

r = requests.get("https://geoapi.world/api/country.php", params={
    "code": "DE", "lang": "de", "admin1": 1, "flag": 1
})
data = r.json()

c = data["country"]
print(f"Land: {c['name']}")
print(f"Hauptstadt: {c['capital']}")
print(f"Währung: {c['currency_code']} ({c['currency_name']})")
for r in c["admin1"]:
    print(f"  - {r['name']}")

Antwort enthält das vollständige Country-Objekt — gut für Localization-Setup (Currency, Phone, Postal-Format), für Hierarchie-Picker mit Bundesländern, oder für Steuer-/Recht-Logik.

📍 Region-Detail GET /api/region.phpIm Playground testen ↗

Bundesland/Kanton/Provinz inkl. Country-Kontext.

Parameter

NameBeschreibung
codePflichtFormat ISO2.AdminCode: DE.02 = Bayern, CH.ZH = Zürich, US.CA = Kalifornien.
langISO-Sprachcode.
flag1 = ergänzt flag_url (Flagge des übergeordneten Landes).
curl -s 'https://geoapi.world/api/region.php?code=DE.02&lang=de'
<?php
$url  = "https://geoapi.world/api/region.php?" . http_build_query([
    "code" => "DE.02", "lang" => "de",
]);
$data = json_decode(file_get_contents($url), true);

$r = $data["region"];
echo $r["name"] . " (" . $r["country_name"] . ")\n";
echo "Code: " . $r["qualified"] . "\n";
const url = "https://geoapi.world/api/region.php?" + new URLSearchParams({
  code: "DE.02", lang: "de"
});
const data = await (await fetch(url)).json();

const r = data.region;
console.log(`${r.name} (${r.country_name})`);
console.log("Code:", r.qualified);
import requests

resp = requests.get("https://geoapi.world/api/region.php",
                    params={"code": "DE.02", "lang": "de"})
data = resp.json()

r = data["region"]
print(f"{r['name']} ({r['country_name']})")
print(f"Code: {r['qualified']}")

Liefert code, qualified, country_code, country_name, name, name_ascii, geonameid, flag_url.

📍 Flagge GET /api/flag.phpIm Playground testen ↗

Default: 302-Redirect zur SVG-Datei. Mit ?as=json: JSON-Antwort mit der Flag-URL.

Parameter

NameBeschreibung
codePflichtISO-2-Ländercode.
asjson = JSON-Antwort statt 302-Redirect.
# Direkt zur SVG (302):
curl -sL 'https://geoapi.world/api/flag.php?code=DE' -o flag.svg

# Als JSON:
curl -s 'https://geoapi.world/api/flag.php?code=DE&as=json'
<!-- Direkt im HTML-Tag — der 302-Redirect wird transparent gefolgt -->
<img src="https://geoapi.world/api/flag.php?code=DE" alt="Flagge DE">

<!-- Oder URL via JSON holen -->
<?php
$json = file_get_contents("https://geoapi.world/api/flag.php?code=DE&as=json");
$data = json_decode($json, true);
echo '<img src="' . htmlspecialchars($data["flag_url"]) . '">';
// Direkt als <img>-Quelle
const img = document.createElement("img");
img.src = "https://geoapi.world/api/flag.php?code=DE";
document.body.appendChild(img);

// Oder URL per JSON holen
const r = await fetch("https://geoapi.world/api/flag.php?code=DE&as=json");
const d = await r.json();
console.log(d.flag_url);
import requests

# requests folgt Redirects automatisch
resp = requests.get("https://geoapi.world/api/flag.php", params={"code": "DE"})
with open("flag.svg", "wb") as f:
    f.write(resp.content)

# Oder URL via JSON
resp = requests.get("https://geoapi.world/api/flag.php",
                    params={"code": "DE", "as": "json"})
print(resp.json()["flag_url"])

233 von 252 ISO-2-Codes haben SVG-Flaggen. Bei fehlender SVG: 404 (oder {"error":"…"} mit ?as=json).

📍 Health GET /api/health.phpIm Playground testen ↗

UptimeRobot-/StatusCake-kompatibler Health-Check. Status 200 wenn DB erreichbar, 503 sonst.

curl -sf 'https://geoapi.world/api/health.php' && echo OK
<?php
$ctx = stream_context_create(["http" => ["ignore_errors" => true]]);
$json = file_get_contents("https://geoapi.world/api/health.php", false, $ctx);
$data = json_decode($json, true);

if ($data["status"] === "ok") {
    echo "API erreichbar (DB: " . $data["db_ms"] . " ms)";
} else {
    error_log("geoAPI ist gestört");
}
const r = await fetch("https://geoapi.world/api/health.php");
if (r.ok) {
  const d = await r.json();
  console.log(`API erreichbar (DB: ${d.db_ms} ms)`);
} else {
  console.warn("API ist gestört");
}
import requests

r = requests.get("https://geoapi.world/api/health.php")
if r.ok:
    print(f"API erreichbar (DB: {r.json()['db_ms']} ms)")
else:
    print("API ist gestört")

Externes Monitoring braucht nur den HTTP-Statuscode zu prüfen. Antwort-Felder: status, db_ok, db_ms, php_version, duration_ms, timestamp.