I have a coordinate, and I want to know what Commons categories are nearby.

For instance, for 40.7576,-73.9857 I would get Category:Times Square and probably Category:Broadway and a few others nearby.

Is there an API that gives this?

If not, is there a way to get the same via several APIs calls? 50% of false positives is OK.

Note: Once again, my question is about Wikimedia Commons categories.


4 Answers 4


You can use WikiData SPARQL service to run it

SELECT ?place ?location ?distance ?placeLabel ?commons WHERE {
  ?place wdt:P373 ?commons.
  SERVICE wikibase:around { 
    ?place wdt:P625 ?location .

    bd:serviceParam wikibase:center "Point(-73.9857 40.7576)"^^geo:wktLiteral .
    bd:serviceParam wikibase:radius "1" . 
    bd:serviceParam wikibase:distance ?distance .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ?distance LIMIT 100

Run it in query service: https://w.wiki/FQ4


There is a more direct way to get this from Wikidata, if you want an API. That's the API used by AutoList. Returns JSON or JSONP.

Example query to retrieve all Commons categories within 0.1 kilometer from 40.7576,-73.9857:

  • http://wdq.wmflabs.org/api?q=claim[373]%20and%20around[625,40.7576,-73.9857,0.1]&props=373
  • Live

Explanation of the request:

  • 373 is the property id of the Commons category item
  • around takes as arguments: PROPERTY,LATITUDE,LONGITUDE,RADIUS
  • 625 is the property id of the coordinate location item
  • The &props=373 part can be removed if only identifiers are needed


    "status": {
        "error": "OK",
        "items": 8,
        "querytime": "1333ms",
        "parsed_query": "(CLAIM[373] AND AROUND[625,40.7576,-73.9857,0.1])"
    "items": [11259, 626926, 659652, 827638, 1756846, 1973105, 3062716, 3363532],
    "props": {
        "373": [
            [1973105, "string", "2010 Times Square car bombing attempt"],
            [827638, "string", "Bertelsmann Building"],
            [1756846, "string", "Lyceum Theatre (Broadway)"],
            [3062716, "string", "Minskoff Theatre"],
            [659652, "string", "One Astor Plaza"],
            [3363532, "string", "Paramount Building (New York City)"],
            [11259, "string", "Times Square"],
            [626926, "string", "V-J Day in Times Square (Alfred Eisenstaedt)"]

The server response is rather slow, and seems to increase with the number of categories returned.

See the full documentation.

  • Your example return mostly articles, whereas my question asks for Wikimedia Commons categories. By the way, Commons categories are different from Wikipedia categories, they follow different hierarchy/granularity rules.
    – Nicolas Raoul
    Oct 5, 2015 at 3:21
  • @NicolasRaoul Those are categories - scroll down to the "props":{"373": section, and all the text after that point is category strings. Q655136 is a good demonstration, as the returned P373 label is appended with (Manhattan) while the Wikidata label doesn't have it. Oct 5, 2015 at 7:40
  • (This is a much more efficient approach than my answer, which generates a human-readable list rather than an API-readable one.) Oct 5, 2015 at 7:42
  • @Andrew: What directly follows "props":{"373": is 1859121, 209017, 284013, none of which are Commons categories, they are actually just Wikipedia articles. The text "1 Hanover Square"/etc are the same Wikipedia articles.
    – Nicolas Raoul
    Oct 5, 2015 at 8:11
  • 1
    @Andrew: I somehow expected a "commons" section and did not think to look for a property, now I understand, thanks!
    – Nicolas Raoul
    Oct 5, 2015 at 8:49

Wikidata can do it!

Using autolist, run the query claim[373] and around[625,40.7576,-73.9857,50] [link].

This will give you all items with a commons category property (P373) and a location (P625) up to 50km from 40.7576,-73.9857.

At the time of writing, this is 1900 entries. Dropping it to 10km is 1146, and 1km is 141.

(This won't get subcategories of these Commons categories unless they also have properties with geocoordinates, but it's certainly a start.)

To get a list of all commons categories from this set, ask it to generate a PagePile listing, then from the next page select item properties, and then property 373 and 625 when it loads the TABernacle tool. This will give you a nice little downloadable text file with item, commons category, & coordinates. For the 1km set (141 places), this will give you the following results.


There does not seem to be a Wikipedia API. It looks like geonames.org has some of this functionality though.

For example, take a look at the results of this page: http://www.geonames.org/maps/google_40.7576_-73.9857.html

I took a look at the API requests on that page and it called the following:


That being said, it looks like this Wikipedia Search with a Bounding Box geonames.org API at http://www.geonames.org/export/wikipedia-webservice.html#wikipediaBoundingBox is what you would want though you may need to programatically filter out anything not a category.

Hope this helps.

  • It seems to return only articles, no categories... Also, I am looking for Wikimedia Commons categories. Commons categories are different from Wikipedia categories, they follow different hierarchy/granularity rules.
    – Nicolas Raoul
    Oct 2, 2015 at 4:31
  • @NicolasRaoul - sorry, didnt understand that nuance. My bad :) Oct 2, 2015 at 20:03

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.