简体   繁体   中英

How to include distance in co-ordinates using Wikipedia API?

In my Wikipedia API I get Co-ordinate of a place. This co-ordinate contain lat, lon, dim, type etc. But I also want to add dist inside the co-ordinates so that I can get distance of each places from one API. My current API is -

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

The output of this API is:

"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...
    ]
}

While searching for queries dist of location, I found the below API:

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

The output of this API is:

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

Now I want to know is there any way to include "dist" in my previous API?

Yes, you can include dist in your API by using codistancefrompoint parameter, which is a part from coordinates used already in your main API request, so you don't need to use another API. The value for this parameter has to be the your entry point, so it has to be the same as the ggscoord :

codistancefrompoint=52.5243700|13.4105300

In this case for each one result the distance will be measured from this entry point to the result point.

Here is your new API query:

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

And here is the result:

"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
            }
        },
        ...
    ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM