35

Is it possible, using the existing Wikipedia API's to get a list of articles around a Geo-location? Sort of like how Google maps does it?

I would like to say that I am "here" and find out what is around me on Wikipedia.

I can see on articles like this you can see the "Coordinates" on the right hand side, so I would like to do a query on these coordinates...

any thoughts?

Damjan Pavlica
  • 31,277
  • 10
  • 71
  • 76
Mark
  • 14,820
  • 17
  • 99
  • 159

8 Answers8

27

UPDATED ANSWER:
Wikilocation has been retired and now there is an OFFICIAL WIKIPEDIA API

? action=query
& list=geosearch
& gsradius=<radius-in-meters>
& gscoord=<lat>|<lon>

HTML example | JSON Example

ZJR
  • 9,308
  • 5
  • 31
  • 38
16

Don't reinvent the wheel, use DBpedia.
Sample page with "lat" and "lon" data extracted.
And it can be queried with SPARQL.

Adrian Farmadin
  • 407
  • 2
  • 11
lambshaanxy
  • 22,552
  • 10
  • 68
  • 92
10

This is nowadays built into Wikipedia through Special:Nearby.

https://en.wikipedia.org/wiki/Special:Nearby

Ainali
  • 1,613
  • 13
  • 23
10

Have a look at Wikilocation, might be useful.

xidew
  • 411
  • 1
  • 5
  • 12
  • 2
    UPDATE: Wikilocation has been retired and now there is an [OFFICIAL WIKIPEDIA API](https://www.mediawiki.org/wiki/Extension:GeoData#API) – ZJR Dec 23 '14 at 03:22
5

It seems like there is no Wikipedia API for this, but this Wikipedia page describes how others make use of this information:

All coordinates are available for download in Wikipedia database dumps. To get the coordinates from the XML format dump of all articles (enwiki-latest-pages-articles.xml.bz2, 4 GB), the dump needs to be parsed for pages containing coordinates in the entry formats listed above. Most articles in Wikipedia conform to these formats and coordinates are easy to parse from the wikitext with regular expressions for simple character sequences. As all coordinates link to the same PHP tool, they may also be found from the SQL format table of external links (enwiki-latest-externallinks.sql.gz, 725MB). This second method will however not include all available information about the coordinates, such as their position between the article body and the title area.

Philipp
  • 11,549
  • 8
  • 66
  • 126
  • Thanks Philipp, I did manage to get some DB dumps, its a pity that you have to go down this path. But like I commented, I might just use the http://www.geonames.org/export/wikipedia-webservice.html#findNearbyWikipedia service for now... – Mark Nov 16 '10 at 06:32
  • 1
    The coordinates are actually pretty time consuming to parse as they come in few different formats. See http://en.wikipedia.org/wiki/Template:Coord for more details about the formats. – Filip Aug 16 '12 at 19:30
5

Solution jquery and geonames API:

a,b = longitude, latitude, tweet -> html div

function getcontent(a,b) {
    jQuery(function($) {
        $.getJSON('http://api.geonames.org/findNearbyWikipediaJSON?formatted=true&lat='+ a +'&lng='+ b +'&username=username&style=full&lang=de&wikipediaUrl&thumbnailImg', function(json) {
            for(var i = 0; i < json.geonames.length; i++) {
                $("#tweet").prepend('<span style="font-family: geneva, arial, helvetica, sans-serif;"><br><br><img src="wikilogo.gif"><br>' + json.geonames[i].summary + '<br><a href="http://'+ json.geonames[i].wikipediaUrl +'" target="_blank">'+ json.geonames[i].wikipediaUrl +'</a><br></span>');
            }
        }); 
    }); 
}
gevorg
  • 4,835
  • 4
  • 35
  • 52
mboeckle
  • 938
  • 13
  • 29
3

I know, this is an old question, but here is the URL format for a similar query:

https://en.wikipedia.org/w/api.php?action=query&list=geosearch&format=json&gscoord=40.418670|-3.699389&gsradius=10000&gslimit=10

after &gscoord= you should put the coordinates separated by |, and after &gsradius= the search radius in meters, gslimit is the max number of entries in response.

The response contains JSON.

Dale K
  • 25,246
  • 15
  • 42
  • 71
1

DBpedia and SPARQL are not good options, at least not for the German Wikipedia: The coverage is too small.

I'm trying to parse all the different geo coordinate formats by myself right now (from the dumps), but that's quite difficult as there are really a lot of different variants.

j0k
  • 22,600
  • 28
  • 79
  • 90