2016-03-09 30 views
1

在我的維基百科API中,我得到了一個地方的座標。這個座標包含lat,lon,dim,type等。但是我也想在座標裏面添加dist,這樣我就可以從一個API獲得每個地方的距離。我現在的API是 -如何使用維基百科API在座標中包含距離?

https://en.wikipedia.org/w/api.php?format=json&action=query&redirects=1&generator=geosearch&prop=extracts|coordinates|pageimages&ggslimit=20&ggsradius=1000&ggscoord=52.5243700|13.4105300&&formatversion=2&exintro=1&explaintext=1&exlimit=20&coprop=type|dim|globe&colimit=20&piprop=thumbnail&pithumbsize=400&pilimit=20 

這個API的輸出是:

"query": { 
    "pages": [ 
     { 
      "pageid": 2511, 
      "ns": 0, 
      "title": "Alexanderplatz", 
      "extract": "Alexanderplatz (pronounced [ʔalɛkˈsandɐˌplats]) is a large public square and transport hub in the central Mitte district of Berlin, near the Fernsehturm. Berliners often call it simply Alex, referring to a larger neighbourhood stretching from Mollstraße in the northeast to Spandauer Straße and the Rotes Rathaus in the southwest.", 
      "coordinates": [ 
       { 
        "lat": 52.52166748, 
        "lon": 13.41333294, 
        "primary": "", 
        "type": "landmark", 
        "dim": "1000", 
        "globe": "earth" 
       } 
      ], 
      "thumbnail": { 
       "source": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/da/Alexanderplatz_by_the_night_-_ProtoplasmaKid.webm/400px--Alexanderplatz_by_the_night_-_ProtoplasmaKid.webm.jpg", 
       "width": 400, 
       "height": 225 
      } 
     }, 
    ...and some many JSON object similar like this... 
    ] 
} 

當搜索位置的查詢DIST,我發現下面的API:

https://en.wikipedia.org/w/api.php?action=query&list=geosearch&gscoord=37.786952%7C-122.399523&gsradius=10000&gslimit=10 

的輸出這個API是:

"query": { 
    "geosearch": [ 
     { 
      "pageid": 18618509, 
      "ns": 0, 
      "title": "Wikimedia Foundation", 
      "lat": 37.78697, 
      "lon": -122.399677, 
      "dist": 13.7, 
      "primary": "" 
     }, 
     ... so on 
    ] 
} 

現在我想知道是否有任何方法在我以前的API中包含「dist」?

回答

2

是的,你可以通過使用codistancefrompoint參數,這是從你的主API請求中已經使用coordinates部分包括你的API中dist,這樣你就不會需要使用另一個API。此參數的值必須是您的條目點,所以它必須是一樣的ggscoord

codistancefrompoint=52.5243700|13.4105300 

在這種情況下對於每一個結果的距離將來自該進入點被測量到的結果點。

這是你的新API查詢:

https://en.wikipedia.org/w/api.php?format=json&action=query&redirects=1&generator=geosearch&prop=extracts|coordinates|pageimages&ggslimit=20&ggsradius=1000&ggscoord=52.5243700|13.4105300&formatversion=2&exintro=1&explaintext=1&exlimit=20&coprop=type|dim|globe&colimit=20&piprop=thumbnail&pithumbsize=400&pilimit=20&codistancefrompoint=52.5243700|13.4105300 

這裏是結果:

"query":{ 
    "pages":[ 
     { 
      "pageid":2511, 
      "ns":0, 
      "title":"Alexanderplatz", 
      "extract":"Alexanderplatz (pronounced [ʔalɛkˈsandɐˌplats]) is a large public square and transport hub in the central Mitte district of Berlin, near the Fernsehturm. Berliners often call it simply Alex, referring to a larger neighbourhood stretching from Mollstraße in the northeast to Spandauer Straße and the Rotes Rathaus in the southwest.", 
      "coordinates":[ 
       { 
        "lat":52.52166748, 
        "lon":13.41333294, 
        "primary":"", 
        "type":"landmark", 
        "dim":"1000", 
        "globe":"earth", 
        "dist":355.3 
       } 
      ], 
      "thumbnail":{ 
       "source":"https://upload.wikimedia.org/wikipedia/commons/thumb/d/da/Alexanderplatz_by_the_night_-_ProtoplasmaKid.webm/400px--Alexanderplatz_by_the_night_-_ProtoplasmaKid.webm.jpg", 
       "width":400, 
       "height":225 
      } 
     }, 
     ... 
    ] 
} 
+0

非常感謝您的回答。 –