apiwikipediawikipedia-api

Wikipedia API - Returning coordinates for some pages and not others?


For instance, the following page has the coordinates at the top of the page:

https://en.wikipedia.org/?curid=5839303

and I am able to retrieve them via the API

https://en.wikipedia.org/w/api.php?format=json&action=query&prop=coordinates&pageids=5839303

However this page:

https://en.wikipedia.org/?curid=56846583

Has the coordinates in an infobox and not at the top of the page. I am unable to retrieve them via the API:

https://en.wikipedia.org/w/api.php?format=json&action=query&prop=coordinates&pageids=56846583

Does anyone know why this behaviour occurs and whether it's possible to retrieve the coordinates from my second example via the API?


Solution

  • prop=coordinates, by default, only returns the primary coordinate of the page. Try adding coprimary=all to your query: https://en.wikipedia.org/w/api.php?format=json&action=query&prop=coordinates&pageids=56846583&coprimary=all