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?

3
  • 1
    You might even be able to use Google maps's API to get results from their Wikipedia layer. Commented Nov 16, 2010 at 4:51
  • 2
    just found this: geonames.org/export/… which might help me out...
    – Mark
    Commented Nov 16, 2010 at 5:00
  • @BennyJobigan Can you elaborate?
    – x-yuri
    Commented Sep 26, 2016 at 14:40

8 Answers 8

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

16

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

3
  • 1
    Interesting, I did not know that project even existed! Thanks Ill take a good look at it :)
    – Mark
    Commented Nov 18, 2010 at 2:27
  • 1
    @jpatokal: how to use dbpedia to solve the problems OP posted? can u shed some light on this?
    – Abhinav
    Commented Feb 7, 2018 at 13:00
  • 1
    Nowadays, this is implemented in query.wikidata.org.
    – Pere
    Commented Dec 26, 2022 at 20:29
10

Have a look at Wikilocation, might be useful.

1
10

This is nowadays built into Wikipedia through Special:Nearby.

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

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.

2
  • 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 geonames.org/export/… service for now...
    – Mark
    Commented Nov 16, 2010 at 6:32
  • 1
    The coordinates are actually pretty time consuming to parse as they come in few different formats. See en.wikipedia.org/wiki/Template:Coord for more details about the formats.
    – Filip
    Commented Aug 16, 2012 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>');
            }
        }); 
    }); 
}
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.

0
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.