I would like to retrieve images from Wikimedia Commons to display on a map. This means that given a pair (latitude, longitude) I would like to find pictures around this point. After a day of searching and trying I have still no idea whether this is possible or not. In particular I have read MediaWiki API Main page, the API reference and some examples.
So my question is: is it possible to retrieve pictures with a pair of geographical coordinates? If yes, how?
Yeah, that's possible. On Commons, Extension:GeoData is installed. Use
action=query&list=geosearch&gscoord=lat|lon&gsradius=meters&gsnamespace=6&gsprimary=all
Excerpt from the API documentation
File namespace is NS 6 in MediaWiki by default.
Example: https://commons.wikimedia.org/w/api.php?format=jsonfm&action=query&list=geosearch&gsprimary=all&gsnamespace=6&gsradius=500&gscoord=51.5|11.95
Result:
If you additionally want to optain thumbnail urls with your API request, use
list=geosearch
as a generator:Example: https://commons.wikimedia.org/w/api.php?format=jsonfm&action=query&generator=geosearch&ggsprimary=all&ggsnamespace=6&ggsradius=500&ggscoord=51.5|11.95&ggslimit=1&prop=imageinfo&iilimit=1&iiprop=url&iiurlwidth=200&iiurlheight=200
Result: