Just a quick one on here regarding the use of the MediaWiki API. In essence I can retrieve using the MediaWiki API, just the first two sentences of the first paragraph extract of the titled page using:
https://en.wikipedia.org/w/api.php?action=query&prop=extracts&explaintext&exsentences=2&format=xml&titles=Lincoln,%20Massachusetts
Notably here one refers to what page to retrieve this from with the "&titles=" parameter. However, my question is, can you search and retrieve the same information by using longitude and latitude coordinates instead? ie from google maps. If not, is there another API that can be used to retrieve the same result?
You can retrieve this information by using the same Wikipedia API with generator=geosearch:
https://en.wikipedia.org/w/api.php?action=query&generator=geosearch&ggsradius=100&ggscoord=42.425833|-71.304444&prop=extracts
You can play with the radius from 10 to 10,000 [m]. This example is for Lincoln, Massachusetts (latitude and longitude are respectively 42.425833
and -71.304444
).
Second variant is to use WikidataQuery API. This is for the same example:
http://wdq.wmflabs.org/api?q=around[625,42.425833,-71.304444,0.1]
Here the radius is in [km] (the last value in array 0.1
), and 625
(the first value) is coordinate location (P625) Wikidata property. From this you get absolutely the same result: Wikidata item Q663035, which correspond to Lincoln, Massachusetts Wikipedia article.
See also geosearch in Wikidata API, you can get another interesting information about the location (image, country, elevation, etc...)
You can also try SPARQL query service.