forked from wikimedia/mediawiki-api-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeoimagesearch.js
More file actions
35 lines (28 loc) · 914 Bytes
/
geoimagesearch.js
File metadata and controls
35 lines (28 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//This file is autogenerated. See modules.json and autogenerator.py for details
/*
geoimagesearch.js
MediaWiki API Demos
Demo of `Geosearch` module: Use generator module
to get search results for pages near Wikimedia HQ
with images
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
generator: "geosearch",
prop: "coordinates|pageimages",
ggscoord: "37.7891838|-122.4033522",
format: "json"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {
var pages = response.query.pages;
for (var page in pages) {
console.log(pages[page].title + ": " + pages[page].thumbnail.source);
}
})
.catch(function(error){console.log(error);});