Disclosure: I built the Apify Actor mentioned near the end of this post.
To get coordinates from a Wikipedia article, call the MediaWiki Action API with action=query&prop=coordinates&titles=<title>: it returns lat, lon and globe from the article's coordinate template, with no API key. You can pass up to 50 titles in one request, but set colimit=max (the default of 10 coordinates per request silently drops pages), add redirects=1, and expect some articles to have no coordinates at all. For those, the linked Wikidata item's "coordinate location" (P625) is a useful fallback. To go the other way, from a point on the map to nearby articles, use list=geosearch.
Below is standard-library Python for all three, with the output of a real run on 2026-12-01.
Where do Wikipedia's coordinates come from?
When an editor adds a {{Coord}} template to an article, the GeoData extension stores those coordinates, and the API serves them through two modules:
| Module | What it does | Docs |
|---|---|---|
prop=coordinates | Coordinates of the pages you name | API:Coordinates |
list=geosearch | Pages near a point (or near another page) | API:Geosearch |
Two terms matter:
- Primary coordinates are the ones that describe the article's subject (the ones shown at the top of the page). An article has at most one primary point.
- Secondary coordinates are other places mentioned in the article: the source of a river, a capital city inside a country article.
prop=coordinatesreturns only the primary point unless you passcoprimary=all.
Coordinates are not limited to Earth: each point has a globe field (earth, moon, mars…).
How do I get coordinates for one or many articles in Python?
The script below takes a list of titles and prints one CSV row per title. It:
- asks for 50 titles per request (the Action API limit for anonymous clients),
- sets
colimit=maxand followscontinue, so no page loses its coordinates, - resolves redirects and title normalisation back to your original input,
- reads the linked Wikidata item ID (
pageprops.wikibase_item) in the same request, - for pages without primary coordinates, fetches P625 from Wikidata with
wbgetentities(50 IDs per request).
Replace the contact in UA with your own: Wikimedia's User-Agent policy asks every client to identify itself.
import csv import json import sys import time from urllib.error import HTTPError from urllib.parse import urlencode from urllib.request import Request, urlopen UA = "devto-example-script/1.0 (contact: you@example.com)" def get_json(url, params, tries=4): full = url + "?" + urlencode(params) for attempt in range(tries): try: with urlopen(Request(full, headers={"User-Agent": UA}), timeout=30) as r: data = json.load(r) time.sleep(1) # one request at a time, about one per second return data except HTTPError as e: if e.code in (429, 503) and attempt < tries - 1: time.sleep(int(e.headers.get("Retry-After") or 5)) continue raise def article_coords(titles, lang="en"): """Primary coordinates for up to thousands of titles, 50 per request.""" api = f"https://{lang}.wikipedia.org/w/api.php" out = {} for i in range(0, len(titles), 50): chunk = titles[i:i + 50] params = { "action": "query", "format": "json", "formatversion": 2, "prop": "coordinates|pageprops", "ppprop": "wikibase_item", "coprimary": "all", "colimit": "max", "redirects": 1, "titles": "|".join(chunk), "maxlag": 5, } pages, alias = {}, {t: t for t in chunk} while True: data = get_json(api, params) q = data.get("query", {}) for step in q.get("normalized", []) + q.get("redirects", []): for src, dst in alias.items(): if dst == step["from"]: alias[src] = step["to"] for p in q.get("pages", []): page = pages.setdefault(p["title"], {"missing": "missing" in p, "coords": [], "qid": None}) page["coords"] += p.get("coordinates", []) page["qid"] = page["qid"] or p.get("pageprops", {}).get("wikibase_item") if "continue" not in data: break params.update(data["continue"]) for src, title in alias.items(): page = pages.get(title, {"missing": True, "coords": [], "qid": None}) primary = [c for c in page["coords"] if c.get("primary")] out[src] = { "title": title, "missing": page["missing"], "qid": page["qid"], "lat": primary[0]["lat"] if primary else None, "lon": primary[0]["lon"] if primary else None, "globe": primary[0]["globe"] if primary else None, "secondary": len(page["coords"]) - len(primary), } return out def wikidata_p625(qids): """Fallback: coordinate location (P625) from Wikidata, 50 items per request.""" found = {} for i in range(0, len(qids), 50): data = get_json("https://www.wikidata.org/w/api.php", { "action": "wbgetentities", "format": "json", "props": "claims", "ids": "|".join(qids[i:i + 50]), "maxlag": 5, }) for qid, entity in data.get("entities", {}).items(): claims = [c for c in entity.get("claims", {}).get("P625", []) if c["rank"] != "deprecated" and c["mainsnak"].get("snaktype") == "value"] claims.sort(key=lambda c: c["rank"] != "preferred") if claims: v = claims[0]["mainsnak"]["datavalue"]["value"] globe = "earth" if v["globe"].endswith("/Q2") else v["globe"] found[qid] = (v["latitude"], v["longitude"], globe) return found if __name__ == "__main__": titles = ["Eiffel Tower", "UK", "Danube", "Battle of Hastings", "Route 66", "Ada Lovelace", "Tranquility Base", "Atlantis (fake page)"] rows = article_coords(titles) need = [r["qid"] for r in rows.values() if r["lat"] is None and r["qid"]] p625 = wikidata_p625(need) if need else {} w = csv.writer(sys.stdout) w.writerow(["input", "title", "lat", "lon", "globe", "secondary", "source"]) for src, r in rows.items(): lat, lon, globe, source = r["lat"], r["lon"], r["globe"], "wikipedia" if lat is None and r["qid"] in p625: (lat, lon, globe), source = p625[r["qid"]], "wikidata P625" elif lat is None: source = "missing page" if r["missing"] else "none" w.writerow([src, r["title"], lat, lon, globe, r["secondary"], source]) Output (Python 3.9, 2026-12-01, run twice with identical output):
input,title,lat,lon,globe,secondary,source Eiffel Tower,Eiffel Tower,48.85822222,2.2945,earth,0,wikipedia UK,United Kingdom,55,-3,earth,1,wikipedia Danube,Danube,45.2175,29.76138889,earth,3,wikipedia Battle of Hastings,Battle of Hastings,50.91444444444444,0.48777777777777775,earth,0,wikidata P625 Route 66,U.S. Route 66,39.006952,-89.77948,earth,0,wikidata P625 Ada Lovelace,Ada Lovelace,,,,0,none Tranquility Base,Tranquility Base,0.6875,23.43333333,moon,1,wikipedia Atlantis (fake page),Atlantis (fake page),,,,0,missing page What each row shows:
- Eiffel Tower: one primary point, nothing else.
- UK was redirected to United Kingdom. The primary point is a rough centre of the country (55, -3); the one secondary point is London.
- Danube: primary point at the mouth on the Black Sea, plus three secondary points around its source area in the Black Forest.
- Battle of Hastings and U.S. Route 66 have no coordinates on English Wikipedia on this date, so the script fell back to Wikidata P625. For a road, P625 is a single representative point, not the route.
- Ada Lovelace: a person, no coordinates anywhere. That is normal, not an error.
- Tranquility Base:
globeismoon. If you plot everything on an Earth map, filter onglobefirst. - Atlantis (fake page): the page does not exist; the API marks it
missing.
The script sends one request at a time and sleeps a second after each, well under the limits on Wikimedia's rate limits page. It also passes maxlag=5, which tells the servers to refuse the request when they are lagging. I did not hit a 429, a 503 or a maxlag refusal during testing, so the retry branch is untested. I also only ran 8 titles, so the split into batches of 50 ran as a single batch.
Why does the API return coordinates for some pages and not others?
This is a frequent question (one example on Stack Overflow). There are three different reasons, and only one is about the data.
1. You hit colimit. colimit counts coordinates across the whole request, not per page, and the default is 10. Ask for 15 landmarks without it:
from wiki_coords import get_json titles = ["Eiffel Tower", "Statue of Liberty", "Big Ben", "Colosseum", "Taj Mahal", "Sydney Opera House", "Golden Gate Bridge", "Machu Picchu", "Petra", "Acropolis of Athens", "Christ the Redeemer (statue)", "Mount Fuji", "Burj Khalifa", "Stonehenge", "Angkor Wat"] data = get_json("https://en.wikipedia.org/w/api.php", { "action": "query", "format": "json", "formatversion": 2, "prop": "coordinates", "titles": "|".join(titles), # no colimit }) with_coords = [p["title"] for p in data["query"]["pages"] if "coordinates" in p] print(len(with_coords), "of", len(titles), "pages have coordinates") print("continue:", data.get("continue")) 10 of 15 pages have coordinates continue: {'cocontinue': '189351|791186175', 'continue': '||'} Five famous landmarks seem to have no coordinates, but the response also has a continue key. Either set colimit=max (500) or follow continue until it disappears. The main script does both: I re-ran it with colimit=1 to force continuation, and the output matched the normal run exactly.
2. The page has only secondary coordinates. With the default coprimary=primary you get nothing back for them. Pass coprimary=all and look at the primary flag yourself.
3. The article really has no coordinates. People, events and abstract topics usually do not. Some places simply have not been tagged yet. That is when the Wikidata P625 fallback helps. Wikidata is a separate, editor-maintained source, so treat its point as a second opinion and keep the source column.
How do I find Wikipedia articles near a location?
list=geosearch takes a point and a radius in metres. From action=paraminfo on 2026-12-01: gsradius is 10 to 10,000 (default 500) and gslimit defaults to 10, maximum 500. This reuses get_json from the script above:
from wiki_coords import get_json def nearby(lat, lon, radius_m=1000, limit=10, lang="en"): data = get_json(f"https://{lang}.wikipedia.org/w/api.php", { "action": "query", "format": "json", "formatversion": 2, "list": "geosearch", "gscoord": f"{lat}|{lon}", "gsradius": radius_m, "gslimit": limit, "maxlag": 5, }) return data["query"]["geosearch"] for p in nearby(48.85822222, 2.2945, radius_m=500, limit=5): print(f'{p["dist"]:>6} m {p["lat"]:.5f}, {p["lon"]:.5f} {p["title"]}') 0 m 48.85822, 2.29450 Eiffel Tower 149.4 m 48.85750, 2.29278 Globe Céleste 161.2 m 48.85830, 2.29230 Palazzo Bernardo Nani 235.8 m 48.85972, 2.29222 Pont d'Iéna 337.6 m 48.85610, 2.29780 Exposition Universelle (1900) The third result is a palace in Venice whose article, on 2026-12-01, carried coordinates next to the Eiffel Tower. Geosearch returns whatever coordinates editors entered, so for a real dataset, cross-check outliers (for example against P625, or a country field) before you trust a point. Instead of gscoord you can pass gspage=<title> to search around another article, and generator=geosearch lets you get coordinates, pageprops or other page properties for the results in the same request.
To cover a larger area such as a whole city, you have to tile it with several 10 km circles and drop duplicate pageids, since one request cannot go past 10,000 m or 500 results.
Is there a hosted option?
If you would rather not run and maintain the script, I built an Apify Actor, Wikipedia Scraper – Articles, Wikidata & Pageviews, that does the title-to-coordinates part. Give it a list of article titles and you get one row per article.
What it returns, from its README:
-
latitudeandlongitudeare the article's primary coordinates, ornullwhen there are none. It does not return secondary points. - Add
"wikidataProperties": ["P625"]to also get Wikidata's coordinate location as{ "latitude": …, "longitude": … }, next to the Wikipedia value, so you can compare or fill gaps. - Input can be titles, article URLs in any language, keyword searches or categories; each row also has the intro summary, main image URL, categories and
sourceUrl, and optionally 30-day pageviews. - It does not do geosearch (radius searches around a point). For that, use the
list=geosearchcode above.
Cost and limits, from the README: US$1.00 per 1,000 articles plus US$0.0005 per run start; Apify's free plan includes US$5 of usage a month, about 5,000 articles. It sends at most 2 requests per second to Wikimedia and a run lasts at most 20 minutes.
It uses Wikimedia's official APIs and is not affiliated with or endorsed by the Wikimedia Foundation.
FAQ
Do I need an API key to get coordinates from Wikipedia?
No. prop=coordinates and list=geosearch are part of the public MediaWiki Action API at https://<language>.wikipedia.org/w/api.php. You only need a descriptive User-Agent header with contact details, as Wikimedia's User-Agent policy asks.
How many articles can I get coordinates for in one request?
Up to 50 titles per request for anonymous clients. Set colimit=max (500), because the default colimit of 10 counts coordinates across all pages in the request, and follow the continue key if it appears.
What is the difference between primary and secondary coordinates?
Primary coordinates describe the article's own subject, and there is at most one per article. Secondary coordinates are other places mentioned in the article, such as a river's source. prop=coordinates returns only primary points unless you pass coprimary=all.
Why does a Wikipedia page have no coordinates?
Either the subject has no location (people, events, concepts) or no editor has added a coordinate template yet. Also check that the request was not cut off by colimit and that you asked for redirects. For places, the linked Wikidata item's P625 property is often filled in when the article is not.
How do I find Wikipedia articles near a latitude and longitude?
Use list=geosearch with gscoord=<lat>|<lon> and gsradius in metres (10 to 10,000). Each result has a title, page ID, coordinates and distance in metres. For larger areas, query several circles and remove duplicate page IDs.
Are Wikipedia coordinates always correct?
No. They are entered by editors. In the test above, a Venice palace showed up 161 m from the Eiffel Tower because of its article's coordinates on that date. Check outliers before using the data, for example against Wikidata P625.
What do you use Wikipedia coordinates for: maps, travel apps, or something else?
Disclosure: I built the Apify Actor mentioned in this post.