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
Response:
{
"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.
"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. – Andrew is gone Oct 05 '15 at 07:40"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 05 '15 at 08:11[1829534,"string","Train stations in Moscow"]. Q1829534 does not have either an English Wikipedia entry or an English label on Wikidata; it does, however, have a Commons category with that title... – Andrew is gone Oct 05 '15 at 08:32