如何使用维基百科 API 在坐标中包含距离?
How to include distance in co-ordinates using Wikipedia API?
在我的维基百科中 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...
]
}
在搜索距离位置的查询时,我发现了以下 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"吗?
是的,您可以使用 codistancefrompoint 参数将 dist
包含在您的 API 中,该参数来自 coordinates 中已经使用的部分您的主要 API 请求,因此您不需要使用另一个 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
}
},
...
]
}
在我的维基百科中 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...
]
}
在搜索距离位置的查询时,我发现了以下 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"吗?
是的,您可以使用 codistancefrompoint 参数将 dist
包含在您的 API 中,该参数来自 coordinates 中已经使用的部分您的主要 API 请求,因此您不需要使用另一个 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
}
},
...
]
}