Get the distance between two locations in android?

前端 未结 10 582
醉梦人生
醉梦人生 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条回答
  •  孤街浪徒
    2020-11-28 08:50

    Use the Google Maps Directions API. You'll need to request the directions over HTTP. You can do this directly from Android, or via your own server.

    For example, directions from Montreal to Toronto:

    GET http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false
    

    You'll end up with some JSON. In routes[].legs[].distance, you'll get an object like this:

         "legs" : [
            {
               "distance" : {
                  "text" : "542 km",
                  "value" : 542389
               },
    

    You can also get the polyline information directly from the response object.

提交回复
热议问题