Wikimedia Commons API image search by (latitude, longitude)

I would like to get images from Wikimedia Commons for display on a map. This means that, given the pair (latitude, longitude), I would like to find photographs around this point. After a day of searching and trying, I still don't know if this is possible or not. In particular, I read the MediaWiki API Homepage , a link to the API, and a few examples .

So my question is: is it possible to get images with two geographic coordinates? If so, how?

+6
source share
1 answer

Yes it is possible. Commons has Extension: GeoData installed . Use action=query&list=geosearch&gscoord= lat | lon &gsradius= meters &gsnamespace=6&gsprimary=all action=query&list=geosearch&gscoord= lat | lon &gsradius= meters &gsnamespace=6&gsprimary=all

Excerpt from API documentation

  gscoord - Coordinate around which to search: two floating-point values separated by pipe (|) gspage - Title of page around which to search gsradius - Search radius in meters This parameter is required The value must be between 10 and 10000 gsmaxdim - Restrict search to objects no larger than this, in meters gslimit - Maximum number of pages to return No more than 500 (5000 for bots) allowed Default: 10 gsnamespace - Namespace(s) to search Values (separate with '|'): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101, 102, 103, 104, 105, 106, 107, 460, 461, 490, 491, 1198, 1199, 828, 829 Maximum number of values 50 (500 for bots) Default: 0 gsprop - What additional coordinate properties to return Values (separate with '|'): type, name, dim, country, region, globe Default: globe 

The 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:

 { "query": { "geosearch": [ { "pageid": 28971703, "ns": 6, "title": "File:RiveuferHerbst.JPG", "lat": 51.501042, "lon": 11.948794, "dist": 142.8 }, { "pageid": 32760810, "ns": 6, "title": "File:Pei\u00dfnitznordspitze4.JPG", "lat": 51.499675, "lon": 11.947992, "dist": 143.6 } ] } } 

If you also want to use sketch thumbnails 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&iipiiuritluritluritluritluritluritluritluritluritur_luritur1lp

Result:

 { "query": { "pages": { "28971703": { "pageid": 28971703, "ns": 6, "title": "File:RiveuferHerbst.JPG", "imagerepository": "local", "imageinfo": [ { "thumburl": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/RiveuferHerbst.JPG/200px-RiveuferHerbst.JPG", "thumbwidth": 200, "thumbheight": 150, "url": "https://upload.wikimedia.org/wikipedia/commons/b/b2/RiveuferHerbst.JPG", "descriptionurl": "https://commons.wikimedia.org/wiki/File:RiveuferHerbst.JPG" } ] } } } } 
+9
source

Source: https://habr.com/ru/post/970163/


All Articles