Muggles
Muggles

Reputation: 1556

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?

Upvotes: 1

Views: 169

Answers (2)

mintymuz
mintymuz

Reputation: 357

Only 10 coordinates are returned, even if your wider query requests more than 10 search results

Documentation for the coordinates parameters

For example, if you were trying to perform a geographical search and you've set the ggslimit limit to 20, to retrieve up to 20 results; you also need to set the colimit to 20, otherwise you will only get coordinates returned for the first default 10 results.

Example query

https://en.wikipedia.org/w/api.php?prop=coordinates&generator=geosearch&action=query&ggslimit=20&coprimary=all&ggscoord=35.6761919%7C139.6503106&ggsradius=2000&format=json&colimit=20

Upvotes: 0

AXO
AXO

Reputation: 9096

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

Upvotes: 1

Related Questions