Get the distance between two locations in android?

前端 未结 10 562
醉梦人生
醉梦人生 2020-11-28 07:57

i need to get distance between two location, but i need to get distance like blue line in the picture. \"picure\"

10条回答
  •  萌比男神i
    2020-11-28 08:46

    You can use any Distance API. Google API is one of the most popular, but there are also some alternatives, like Distance Matrix API: Documentation

    It is very easy to use because you don't need to rewrite code if you were used to using Google Maps API before.

    Here is an example of the request:

    Get: https://api.distancematrix.ai/distancematrix?origins=51.4822656,-0.1933769&destinations=51.4994794,-0.1269979&key=
    

    And this is the response example:

    {
      "destination_addresses":["Westminster Abbey, Westminster, 
      London SW1P 3PA, UK"],
      "origin_addresses":["Chapel, Fulham, London SW6 1BA, UK"],
      "rows":[
        {
          "elements":[
            {
              "distance":{
                "text": "4.7 miles",
                "value": 7563.898
              },
              "duration":{
                "text": "28 min",
                "value": 1680
              },
              "duration_in_traffic":{
                "text": "28 min",
                "value": 1680
              },
              "status": "OK"
            }
          ]
        }
      ],
      "status": "OK"
    }
    

    Disclaimer: I work at a company that creates this API.

提交回复
热议问题