farso92 farso92 - 3 months ago 34
Ajax Question

How get coordinates from MediaWiki

I have to do a web interface with a map inside... this map should take the coordinates of some place/city/or something else from the Wikipedia database.
I read something about MediaWiki api but i can't understand how to use it.
At this moment i found this code to take a text from Wikipedia and to put it in a div:

type: "GET",
url: "http://en.wikipedia.org/w/api.php?action=parse&format=json&prop=text&section=0&page=Rome&callback=?",

contentType: "application/json; charset=utf-8",
async: false,
dataType: "json",
success: function (data, textStatus, jqXHR) {
var markup = data.parse.text["*"];
var blurb = $('<div></div>').html(markup);

error: function (errorMessage) {

So I have to change the URL request but I don't understand how.
Thank you


You should be able to get coordinate data out of Wikidata, using the Wikidata Query Service (WDS).

For example, the following query (not very tested) will return some information about things called Rome that have coordinates:

  ?place wdt:P625 ?location .
  ?place rdfs:label ?label .
  FILTER(LANG(?label) = "en") .
  FILTER(STR(?label) = "Rome") .
  ?article schema:about ?place .
  ?article schema:inLanguage "en" .
  ?article schema:isPartOf <https://en.wikipedia.org/> .
} LIMIT 10

You can get the JSON representation of this with a URL like:

https://query.wikidata.org/bigdata/namespace/wdq/sparql?query=<URL-encoded query here>