安卓谷歌地图查找距离

3

我正在尝试找到两个位置之间的距离。我有经纬度,可以计算欧几里得距离。但我想找到道路距离。也就是说,我想在从起点到终点的路上计算道路距离。在这种情况下,该如何计算?

5个回答

7
最简单的方法是使用Google Directions API获取路线指示,这将给您提供沿途所有点的列表(以及总距离)。
请查看:http://code.google.com/apis/maps/documentation/directions/ 如果您不确定如何操作,请告诉我,我会为您发布一些代码,以从Google获取方向并提取所需数据。
更新-按要求发布代码。
private void GetDistance(GeoPoint src, GeoPoint dest) {

    StringBuilder urlString = new StringBuilder();
    urlString.append("http://maps.googleapis.com/maps/api/directions/json?");
    urlString.append("origin=");//from
    urlString.append( Double.toString((double)src.getLatitudeE6() / 1E6));
    urlString.append(",");
    urlString.append( Double.toString((double)src.getLongitudeE6() / 1E6));
    urlString.append("&destination=");//to
    urlString.append( Double.toString((double)dest.getLatitudeE6() / 1E6));
    urlString.append(",");
    urlString.append( Double.toString((double)dest.getLongitudeE6() / 1E6));
    urlString.append("&mode=walking&sensor=true");
    Log.d("xxx","URL="+urlString.toString());

    // get the JSON And parse it to get the directions data.
    HttpURLConnection urlConnection= null;
    URL url = null;

    url = new URL(urlString.toString());
    urlConnection=(HttpURLConnection)url.openConnection();
    urlConnection.setRequestMethod("GET");
    urlConnection.setDoOutput(true);
    urlConnection.setDoInput(true);
    urlConnection.connect();

    InputStream inStream = urlConnection.getInputStream();
    BufferedReader bReader = new BufferedReader(new InputStreamReader(inStream));

    String temp, response = "";
    while((temp = bReader.readLine()) != null){
        //Parse data
        response += temp;
    }
    //Close the reader, stream & connection
    bReader.close();
    inStream.close();
    urlConnection.disconnect();

    //Sortout JSONresponse 
    JSONObject object = (JSONObject) new JSONTokener(response).nextValue();
    JSONArray array = object.getJSONArray("routes");
        //Log.d("JSON","array: "+array.toString());

    //Routes is a combination of objects and arrays
    JSONObject routes = array.getJSONObject(0);
        //Log.d("JSON","routes: "+routes.toString());

    String summary = routes.getString("summary");
        //Log.d("JSON","summary: "+summary);

    JSONArray legs = routes.getJSONArray("legs");
        //Log.d("JSON","legs: "+legs.toString());

    JSONObject steps = legs.getJSONObject(0);
            //Log.d("JSON","steps: "+steps.toString());

    JSONObject distance = steps.getJSONObject("distance");
        //Log.d("JSON","distance: "+distance.toString());

            String sDistance = distance.getString("text");
            int iDistance = distance.getInt("value");

}

该函数将返回两点之间的距离,您可以更改该函数以字符串或整数形式返回它,只需返回sDistance或iDistance即可。
希望这能帮到您,如果您需要更多帮助,请告诉我。

如果你只是想要计算距离,那么Zhehao Mao的答案可能更好一些。但是,一旦你得到了距离,如果你想在地图上绘制路径,那么就使用Directions API。 - Kenny
我查看了您发送的页面,如果您能发送一些代码部分,那对我来说会更好。所以,您能发布一些代码吗? - cemal
我已经将代码添加到我的原始答案中。顺便说一句,在Android上你不能像@Khepri说的那样做 - 虽然这样会更容易! - Kenny
非常感谢您的帮助。它确实对我有所帮助。据我所知,方向 API 通过途经点作为旅行推销员问题的响应来给出顺序。现在还有一个问题是,如何解析这个 JSON 文件。顺序是什么?我的意思是,如果我将参数优化设置为 true,结果会是什么样子?只有优化后的结果吗?而主要问题是如何解析?如果路由器数组中有两条路线,这是什么意思?我认为 legs 是从一个地方到另一个地方的一个方向。但如果是这样,那 route 又是什么呢?非常感谢您的帮助。 - cemal
我尝试了你上面发布的代码,但在Eclipse Android编译时出现以下错误:“JSONTokener无法解析为类型”,对于代码行JSONObject object = (JSONObject) new **JSONTokener**(response).nextValue();。其中一个“修复”方法是导入JSONTokener(org.json),但如果我这样做,它会抛出许多其他错误,例如:对于代码inStream.close();,会出现“未处理的异常类型IOException”。不幸的是,我对Android和Java都很新,所以如果您能提供任何建议,我将非常感激! - Kevin
@Kevin - 你需要导入JSONTokener,你得到错误的原因是因为你必须用try、catch语句包围tokener,以便在发生JSON异常时捕获它们。 - Kenny

5

1

既然你已经在使用Google 地图了,那就看一下驾车路线API吧。

(顺便问一句,是用的Google Maps API v3吗?我猜应该是)

针对一对经纬度点,你可以请求驾车路线

在API3中,它大致是这样的:

var directionsService = new google.maps.DirectionsService();
var start = from; // A Google LatLng point or an address, 
                  // see their API for further details
var end = to;     // A Google LatLng point or an address, 
                  //see their API for further details

var request = {
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};

directionsService.route(request, function (response, status) {
   //Check if status Ok
   //Distance will be in response.routes[0].legs[0].distance.text

});

验证响应状态是否正常,然后确保有路由集合。如果是这样,就有一个结果,您可以通过以下方式访问“distance”文本元素:

response.routes[0].legs[0].distance.text

希望有所帮助。

0

Kenny的改进答案对我有用,我根据自己的想法进行了一些修改。由于引入了LatLng而不是geopoint,因此我发布了经过修改的Kenny答案的工作代码。所有功劳归kenny所有,而不是我!

重要提示:

以字符串格式传递地址。例如:多伦多

复制此函数:

private void GetDistance(String src, String dest) {

        String s = src.replaceAll("\\s","+");
        String d = dest.replaceAll("\\s","+");

        StringBuilder urlString = new StringBuilder();
        urlString.append("http://maps.googleapis.com/maps/api/directions/json?");
        urlString.append("origin=");
        urlString.append((s));
        urlString.append("&destination=");
        urlString.append((d));
        urlString.append("&mode=driving&sensor=true");
        Log.d("xxx", "URL=" + urlString.toString());

        // get the JSON And parse it to get the directions data.
        HttpURLConnection urlConnection = null;
        URL url = null;

        try {
            url = new URL(urlString.toString());
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setRequestMethod("GET");
            urlConnection.setDoOutput(true);
            urlConnection.setDoInput(true);
            urlConnection.connect();

            InputStream inStream = urlConnection.getInputStream();
            BufferedReader bReader = new BufferedReader(new InputStreamReader(inStream));

            String temp, response = "";
            while ((temp = bReader.readLine()) != null) {
                //Parse data
                response += temp;
            }
            //Close the reader, stream & connection
            bReader.close();
            inStream.close();
            urlConnection.disconnect();

            //Sortout JSONresponse
            JSONObject object = (JSONObject) new JSONTokener(response).nextValue();
            JSONArray array = object.getJSONArray("routes");
            Log.d("xxx", "array: " + array.toString());

            //Routes is a combination of objects and arrays
            JSONObject routes = array.getJSONObject(0);
            Log.d("xxx", "routes: " + routes.toString());

            //String summary = routes.getString("summary");
            //Log.d("JSON","summary: "+summary);

            JSONArray legs = routes.getJSONArray("legs");
            Log.d("xxx", "legs: " + legs.toString());

            JSONObject steps = legs.getJSONObject(0);
            Log.d("JSON", "steps: " + steps.toString());

            JSONObject distance = steps.getJSONObject("distance");
            Log.d("xxx", "distance: " + distance.toString());

            String sDistance = distance.getString("text");
            int iDistance = distance.getInt("value");

            Log.d("SEE THE DIST : ", "" + sDistance + iDistance);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

由于此函数执行网络操作,我们必须使用AsyncTask如下:

private class Task extends AsyncTask<Void, Void, Void> {
        @Override
        protected Void doInBackground(Void... params) {
            GetDistance(from, to);
            return null;
        }
    }

日志记录:

01-05 17:01:08.657 3736-3820/in.test D/xxx: URL=http://maps.googleapis.com/maps/api/directions/json?origin=MP+Chowk+Thane+West+Thane,+Maharashtra+400080+&destination=Ghatkopar+West,+Mumbai,+Maharashtra,+India&mode=driving&sensor=true
01-05 17:01:08.687 3736-3736/in.test W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
01-05 17:01:08.687 3736-3736/in.test W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
01-05 17:01:08.797 3736-3778/in.test V/RenderScript: Application requested CPU execution
01-05 17:01:08.807 3736-3778/in.test V/RenderScript: 0xb97768c0 Launching thread(s), CPUs 4
01-05 17:01:09.097 3736-3820/in.test D/xxx: array: [{"bounds":{"northeast":{"lat":19.1885561,"lng":72.9686183},"southwest":{"lat":19.0842303,"lng":72.9075409}},"copyrights":"Map data ©2016 Google","legs":[{"distance":{"text":"15.8 km","value":15818},"duration":{"text":"26 mins","value":1562},"end_address":"Ghatkopar West, Mumbai, Maharashtra, India","end_location":{"lat":19.0908134,"lng":72.9076817},"start_address":"MP Chowk, Thane West, Thane, Maharashtra 400080, India","start_location":{"lat":19.1855772,"lng":72.9556247},"steps":[{"distance":{"text":"27 m","value":27},"duration":{"text":"1 min","value":6},"end_location":{"lat":19.185599,"lng":72.9558468},"html_instructions":"Head <b>northeast<\/b> on <b>MP Chowk<\/b> toward <b>SG Barve Rd<\/b>","polyline":{"points":"{dbtBsch|L?AA?AA?AA??AAAAA?A?A?AAA?A?A?A?A?A?A@A?A@A?A@A?A@A"},"start_location":{"lat":19.1855772,"lng":72.9556247},"travel_mode":"DRIVING"},{"distance":{"text":"0.9 km","value":870},"duration":{"text":"3 mins","value":165},"end_location":{"lat":19.1883648,"lng":72.963413},"html_instructions":"Exit the roundabout onto <b>Lal Bahadur Shastri Marg<\/b><div style=\"font-size:0.9em\">Pass by Wagle Estate Post Office (on the left)<\/div>","polyline":{"points":"_ebtBaeh|LWoAOcAEe@A_AA{AMcBEQC]COOqAk@sDcAaE_@_Ac@}@[o@o@aAk@w@k@w@e@{@s@{AWm@"},"start_location":{"lat":19.185599,"lng":72.9558468},"travel_mode":"DRIVING"},{"distance":{"text":"2.4 km","value":2448},"duration":{"text":"5 mins","value":316},"end_location":{"lat":19.16823,"lng":72.96618509999999},"html_instructions":"Turn <b>right<\/b> to merge onto <b>NH 3<\/b><div style=\"font-size:0.9em\">Partial toll road<\/div>","polyline":{"points":"gvbtBiti|LQYIOCEGKXEZGp@QvM}CnAWLCNCL?X?jFsAp@QlGaBt@Qh@Of@Mz@WXIRI`@MNGRKrB_AxCqAbCaAz@]^Mb@Mr@Ob@IbDg@v@O|B]XEvAW~@OLAPCN?Z?r@@tG^r@Df@F`@HzDt@lAZl@RrAr@bAn@vC`BtD~B"},"start_location":{"lat":19.1883648,"lng":72.963413},"travel_mode":"DRIVING"},{"distance":{"text":"5.6 km","value":5599},"duration":{"text":"5 mins","value":320},"end_location":{"lat":19.1249579,"lng":72.9390226},"html_instructions":"Keep <b>right<\/b> to stay on <b>NH 3<\/b><div style=\"font-size:0.9em\">Partial toll road<\/div>","maneuver":"keep-right","polyline":{"points":"mx~sBuej|LnEnCnElCXNXNtFhDtFhDnc@jW|AbAtL|GZPTN@@@?B@DD@?DB`@X@?rN|I|BtAb@T~X~NzNtHd_@vRhHtDNJh@ZrCzAh@XxAt@lAn@zo@l\\p@ZdCjA~Bz@fGjB"},"start_location":{"lat":19.16823,"lng":72.96618509999999},"travel_mode":"DRIVING"},{"distance":{"text":"1.5 km","value":1518},"duration":{"text":"2 mins","value":95},"end_location":{"lat":19.1122651,"lng":72.93371189999999},"html_instructions":"Keep <b>left<\/b> to stay on <b>NH 3<\/b>","maneuver":"keep-left","polyline":{"points":"_jvsB{{d|LtCt@v@VxAj@jKjDj@Pt`@zLrKfD~HhC"},"start_location":{"lat":19.1249579,"lng":72.9390226},"travel_mode":"DRIVING"},{"distance":{"text":"2.4 km","value":2371},"duration":{"text":"2 mins","value":139},"end_location":{"lat":19.0923682,"lng":72.9255933},"html_instructions":"Keep <b>right<\/b> to stay on <b>NH 3<\/b>","maneuver":"keep-right","polyline":{"points":"uzssBuzc|LrQlFd@Nd@N|XrInBn@zBp@vQpF`F|AjVpH~PfFzAh@"},"start_location":{"lat":19.1122651,"lng":72.93371189999999},"travel_mode":"DRIVING"},{"distance":{"text":"0.9 km","value":921},"duration":{"text":"1 min","value":54},"end_location":{"lat":19.0849757,"lng":72.9217895},"html_instructions":"Continue straight to stay on <b>NH 3<\/b>","maneuver":"straight","polyline":{"points":"i~osB}gb|LZJ|NlEXHTHn@R|@VvAb@tC~@b@NTHh@TB?TJNHZNTL`@T`@Vr@f@d@^`E~C"},"start_location":{"lat":19.0923682,"lng":72.9255933},"travel_mode":"DRIVING"},{"distance":{"text":"0.1 km","value":132},"duration":{"text":"1 min","value":18},"end_location":{"lat":19.0842303,"lng":72.92085449999999},"html_instructions":"Take the exit on the <b>right<\/b> toward <b>Link Rd<\/b>","maneuver":"ramp-right","polyline":{"points":"cpnsBepa|LBV@@@@rBlBDDBDDF@FFT"},"start_location":{"lat":19.0849757,"lng":72.9217895},"travel_mode":"DRIVING"},{"distance":{"text":"0.3 km","value":275},"duration":{"text":"1 min","value":47},"end_location":{"lat":19.0862782,"lng":72.9194201},"html_i
01-05 17:01:09.107 3736-3820/in.test D/xxx: routes: {"bounds":{"northeast":{"lat":19.1885561,"lng":72.9686183},"southwest":{"lat":19.0842303,"lng":72.9075409}},"copyrights":"Map data ©2016 Google","legs":[{"distance":{"text":"15.8 km","value":15818},"duration":{"text":"26 mins","value":1562},"end_address":"Ghatkopar West, Mumbai, Maharashtra, India","end_location":{"lat":19.0908134,"lng":72.9076817},"start_address":"MP Chowk, Thane West, Thane, Maharashtra 400080, India","start_location":{"lat":19.1855772,"lng":72.9556247},"steps":[{"distance":{"text":"27 m","value":27},"duration":{"text":"1 min","value":6},"end_location":{"lat":19.185599,"lng":72.9558468},"html_instructions":"Head <b>northeast<\/b> on <b>MP Chowk<\/b> toward <b>SG Barve Rd<\/b>","polyline":{"points":"{dbtBsch|L?AA?AA?AA??AAAAA?A?A?AAA?A?A?A?A?A?A@A?A@A?A@A?A@A"},"start_location":{"lat":19.1855772,"lng":72.9556247},"travel_mode":"DRIVING"},{"distance":{"text":"0.9 km","value":870},"duration":{"text":"3 mins","value":165},"end_location":{"lat":19.1883648,"lng":72.963413},"html_instructions":"Exit the roundabout onto <b>Lal Bahadur Shastri Marg<\/b><div style=\"font-size:0.9em\">Pass by Wagle Estate Post Office (on the left)<\/div>","polyline":{"points":"_ebtBaeh|LWoAOcAEe@A_AA{AMcBEQC]COOqAk@sDcAaE_@_Ac@}@[o@o@aAk@w@k@w@e@{@s@{AWm@"},"start_location":{"lat":19.185599,"lng":72.9558468},"travel_mode":"DRIVING"},{"distance":{"text":"2.4 km","value":2448},"duration":{"text":"5 mins","value":316},"end_location":{"lat":19.16823,"lng":72.96618509999999},"html_instructions":"Turn <b>right<\/b> to merge onto <b>NH 3<\/b><div style=\"font-size:0.9em\">Partial toll road<\/div>","polyline":{"points":"gvbtBiti|LQYIOCEGKXEZGp@QvM}CnAWLCNCL?X?jFsAp@QlGaBt@Qh@Of@Mz@WXIRI`@MNGRKrB_AxCqAbCaAz@]^Mb@Mr@Ob@IbDg@v@O|B]XEvAW~@OLAPCN?Z?r@@tG^r@Df@F`@HzDt@lAZl@RrAr@bAn@vC`BtD~B"},"start_location":{"lat":19.1883648,"lng":72.963413},"travel_mode":"DRIVING"},{"distance":{"text":"5.6 km","value":5599},"duration":{"text":"5 mins","value":320},"end_location":{"lat":19.1249579,"lng":72.9390226},"html_instructions":"Keep <b>right<\/b> to stay on <b>NH 3<\/b><div style=\"font-size:0.9em\">Partial toll road<\/div>","maneuver":"keep-right","polyline":{"points":"mx~sBuej|LnEnCnElCXNXNtFhDtFhDnc@jW|AbAtL|GZPTN@@@?B@DD@?DB`@X@?rN|I|BtAb@T~X~NzNtHd_@vRhHtDNJh@ZrCzAh@XxAt@lAn@zo@l\\p@ZdCjA~Bz@fGjB"},"start_location":{"lat":19.16823,"lng":72.96618509999999},"travel_mode":"DRIVING"},{"distance":{"text":"1.5 km","value":1518},"duration":{"text":"2 mins","value":95},"end_location":{"lat":19.1122651,"lng":72.93371189999999},"html_instructions":"Keep <b>left<\/b> to stay on <b>NH 3<\/b>","maneuver":"keep-left","polyline":{"points":"_jvsB{{d|LtCt@v@VxAj@jKjDj@Pt`@zLrKfD~HhC"},"start_location":{"lat":19.1249579,"lng":72.9390226},"travel_mode":"DRIVING"},{"distance":{"text":"2.4 km","value":2371},"duration":{"text":"2 mins","value":139},"end_location":{"lat":19.0923682,"lng":72.9255933},"html_instructions":"Keep <b>right<\/b> to stay on <b>NH 3<\/b>","maneuver":"keep-right","polyline":{"points":"uzssBuzc|LrQlFd@Nd@N|XrInBn@zBp@vQpF`F|AjVpH~PfFzAh@"},"start_location":{"lat":19.1122651,"lng":72.93371189999999},"travel_mode":"DRIVING"},{"distance":{"text":"0.9 km","value":921},"duration":{"text":"1 min","value":54},"end_location":{"lat":19.0849757,"lng":72.9217895},"html_instructions":"Continue straight to stay on <b>NH 3<\/b>","maneuver":"straight","polyline":{"points":"i~osB}gb|LZJ|NlEXHTHn@R|@VvAb@tC~@b@NTHh@TB?TJNHZNTL`@T`@Vr@f@d@^`E~C"},"start_location":{"lat":19.0923682,"lng":72.9255933},"travel_mode":"DRIVING"},{"distance":{"text":"0.1 km","value":132},"duration":{"text":"1 min","value":18},"end_location":{"lat":19.0842303,"lng":72.92085449999999},"html_instructions":"Take the exit on the <b>right<\/b> toward <b>Link Rd<\/b>","maneuver":"ramp-right","polyline":{"points":"cpnsBepa|LBV@@@@rBlBDDBDDF@FFT"},"start_location":{"lat":19.0849757,"lng":72.9217895},"travel_mode":"DRIVING"},{"distance":{"text":"0.3 km","value":275},"duration":{"text":"1 min","value":47},"end_location":{"lat":19.0862782,"lng":72.9194201},"html_i
01-05 17:01:09.107 3736-3820/in.test D/xxx: legs: [{"distance":{"text":"15.8 km","value":15818},"duration":{"text":"26 mins","value":1562},"end_address":"Ghatkopar West, Mumbai, Maharashtra, India","end_location":{"lat":19.0908134,"lng":72.9076817},"start_address":"MP Chowk, Thane West, Thane, Maharashtra 400080, India","start_location":{"lat":19.1855772,"lng":72.9556247},"steps":[{"distance":{"text":"27 m","value":27},"duration":{"text":"1 min","value":6},"end_location":{"lat":19.185599,"lng":72.9558468},"html_instructions":"Head <b>northeast<\/b> on <b>MP Chowk<\/b> toward <b>SG Barve Rd<\/b>","polyline":{"points":"{dbtBsch|L?AA?AA?AA??AAAAA?A?A?AAA?A?A?A?A?A?A@A?A@A?A@A?A@A"},"start_location":{"lat":19.1855772,"lng":72.9556247},"travel_mode":"DRIVING"},{"distance":{"text":"0.9 km","value":870},"duration":{"text":"3 mins","value":165},"end_location":{"lat":19.1883648,"lng":72.963413},"html_instructions":"Exit the roundabout onto <b>Lal Bahadur Shastri Marg<\/b><div style=\"font-size:0.9em\">Pass by Wagle Estate Post Office (on the left)<\/div>","polyline":{"points":"_ebtBaeh|LWoAOcAEe@A_AA{AMcBEQC]COOqAk@sDcAaE_@_Ac@}@[o@o@aAk@w@k@w@e@{@s@{AWm@"},"start_location":{"lat":19.185599,"lng":72.9558468},"travel_mode":"DRIVING"},{"distance":{"text":"2.4 km","value":2448},"duration":{"text":"5 mins","value":316},"end_location":{"lat":19.16823,"lng":72.96618509999999},"html_instructions":"Turn <b>right<\/b> to merge onto <b>NH 3<\/b><div style=\"font-size:0.9em\">Partial toll road<\/div>","polyline":{"points":"gvbtBiti|LQYIOCEGKXEZGp@QvM}CnAWLCNCL?X?jFsAp@QlGaBt@Qh@Of@Mz@WXIRI`@MNGRKrB_AxCqAbCaAz@]^Mb@Mr@Ob@IbDg@v@O|B]XEvAW~@OLAPCN?Z?r@@tG^r@Df@F`@HzDt@lAZl@RrAr@bAn@vC`BtD~B"},"start_location":{"lat":19.1883648,"lng":72.963413},"travel_mode":"DRIVING"},{"distance":{"text":"5.6 km","value":5599},"duration":{"text":"5 mins","value":320},"end_location":{"lat":19.1249579,"lng":72.9390226},"html_instructions":"Keep <b>right<\/b> to stay on <b>NH 3<\/b><div style=\"font-size:0.9em\">Partial toll road<\/div>","maneuver":"keep-right","polyline":{"points":"mx~sBuej|LnEnCnElCXNXNtFhDtFhDnc@jW|AbAtL|GZPTN@@@?B@DD@?DB`@X@?rN|I|BtAb@T~X~NzNtHd_@vRhHtDNJh@ZrCzAh@XxAt@lAn@zo@l\\p@ZdCjA~Bz@fGjB"},"start_location":{"lat":19.16823,"lng":72.96618509999999},"travel_mode":"DRIVING"},{"distance":{"text":"1.5 km","value":1518},"duration":{"text":"2 mins","value":95},"end_location":{"lat":19.1122651,"lng":72.93371189999999},"html_instructions":"Keep <b>left<\/b> to stay on <b>NH 3<\/b>","maneuver":"keep-left","polyline":{"points":"_jvsB{{d|LtCt@v@VxAj@jKjDj@Pt`@zLrKfD~HhC"},"start_location":{"lat":19.1249579,"lng":72.9390226},"travel_mode":"DRIVING"},{"distance":{"text":"2.4 km","value":2371},"duration":{"text":"2 mins","value":139},"end_location":{"lat":19.0923682,"lng":72.9255933},"html_instructions":"Keep <b>right<\/b> to stay on <b>NH 3<\/b>","maneuver":"keep-right","polyline":{"points":"uzssBuzc|LrQlFd@Nd@N|XrInBn@zBp@vQpF`F|AjVpH~PfFzAh@"},"start_location":{"lat":19.1122651,"lng":72.93371189999999},"travel_mode":"DRIVING"},{"distance":{"text":"0.9 km","value":921},"duration":{"text":"1 min","value":54},"end_location":{"lat":19.0849757,"lng":72.9217895},"html_instructions":"Continue straight to stay on <b>NH 3<\/b>","maneuver":"straight","polyline":{"points":"i~osB}gb|LZJ|NlEXHTHn@R|@VvAb@tC~@b@NTHh@TB?TJNHZNTL`@T`@Vr@f@d@^`E~C"},"start_location":{"lat":19.0923682,"lng":72.9255933},"travel_mode":"DRIVING"},{"distance":{"text":"0.1 km","value":132},"duration":{"text":"1 min","value":18},"end_location":{"lat":19.0842303,"lng":72.92085449999999},"html_instructions":"Take the exit on the <b>right<\/b> toward <b>Link Rd<\/b>","maneuver":"ramp-right","polyline":{"points":"cpnsBepa|LBV@@@@rBlBDDBDDF@FFT"},"start_location":{"lat":19.0849757,"lng":72.9217895},"travel_mode":"DRIVING"},{"distance":{"text":"0.3 km","value":275},"duration":{"text":"1 min","value":47},"end_location":{"lat":19.0862782,"lng":72.9194201},"html_instructions":"Continue onto <b>Link Rd<\/b><div style=\"font-size:0.9em\">Pass by A 3 (on the left)<\/div>","polyline":{"points":"mknsBija|LIRoDtB{BpAcB`A"
01-05 17:01:09.117 3736-3820/in.test D/JSON: steps: {"distance":{"text":"15.8 km","value":15818},"duration":{"text":"26 mins","value":1562},"end_address":"Ghatkopar West, Mumbai, Maharashtra, India","end_location":{"lat":19.0908134,"lng":72.9076817},"start_address":"MP Chowk, Thane West, Thane, Maharashtra 400080, India","start_location":{"lat":19.1855772,"lng":72.9556247},"steps":[{"distance":{"text":"27 m","value":27},"duration":{"text":"1 min","value":6},"end_location":{"lat":19.185599,"lng":72.9558468},"html_instructions":"Head <b>northeast<\/b> on <b>MP Chowk<\/b> toward <b>SG Barve Rd<\/b>","polyline":{"points":"{dbtBsch|L?AA?AA?AA??AAAAA?A?A?AAA?A?A?A?A?A?A@A?A@A?A@A?A@A"},"start_location":{"lat":19.1855772,"lng":72.9556247},"travel_mode":"DRIVING"},{"distance":{"text":"0.9 km","value":870},"duration":{"text":"3 mins","value":165},"end_location":{"lat":19.1883648,"lng":72.963413},"html_instructions":"Exit the roundabout onto <b>Lal Bahadur Shastri Marg<\/b><div style=\"font-size:0.9em\">Pass by Wagle Estate Post Office (on the left)<\/div>","polyline":{"points":"_ebtBaeh|LWoAOcAEe@A_AA{AMcBEQC]COOqAk@sDcAaE_@_Ac@}@[o@o@aAk@w@k@w@e@{@s@{AWm@"},"start_location":{"lat":19.185599,"lng":72.9558468},"travel_mode":"DRIVING"},{"distance":{"text":"2.4 km","value":2448},"duration":{"text":"5 mins","value":316},"end_location":{"lat":19.16823,"lng":72.96618509999999},"html_instructions":"Turn <b>right<\/b> to merge onto <b>NH 3<\/b><div style=\"font-size:0.9em\">Partial toll road<\/div>","polyline":{"points":"gvbtBiti|LQYIOCEGKXEZGp@QvM}CnAWLCNCL?X?jFsAp@QlGaBt@Qh@Of@Mz@WXIRI`@MNGRKrB_AxCqAbCaAz@]^Mb@Mr@Ob@IbDg@v@O|B]XEvAW~@OLAPCN?Z?r@@tG^r@Df@F`@HzDt@lAZl@RrAr@bAn@vC`BtD~B"},"start_location":{"lat":19.1883648,"lng":72.963413},"travel_mode":"DRIVING"},{"distance":{"text":"5.6 km","value":5599},"duration":{"text":"5 mins","value":320},"end_location":{"lat":19.1249579,"lng":72.9390226},"html_instructions":"Keep <b>right<\/b> to stay on <b>NH 3<\/b><div style=\"font-size:0.9em\">Partial toll road<\/div>","maneuver":"keep-right","polyline":{"points":"mx~sBuej|LnEnCnElCXNXNtFhDtFhDnc@jW|AbAtL|GZPTN@@@?B@DD@?DB`@X@?rN|I|BtAb@T~X~NzNtHd_@vRhHtDNJh@ZrCzAh@XxAt@lAn@zo@l\\p@ZdCjA~Bz@fGjB"},"start_location":{"lat":19.16823,"lng":72.96618509999999},"travel_mode":"DRIVING"},{"distance":{"text":"1.5 km","value":1518},"duration":{"text":"2 mins","value":95},"end_location":{"lat":19.1122651,"lng":72.93371189999999},"html_instructions":"Keep <b>left<\/b> to stay on <b>NH 3<\/b>","maneuver":"keep-left","polyline":{"points":"_jvsB{{d|LtCt@v@VxAj@jKjDj@Pt`@zLrKfD~HhC"},"start_location":{"lat":19.1249579,"lng":72.9390226},"travel_mode":"DRIVING"},{"distance":{"text":"2.4 km","value":2371},"duration":{"text":"2 mins","value":139},"end_location":{"lat":19.0923682,"lng":72.9255933},"html_instructions":"Keep <b>right<\/b> to stay on <b>NH 3<\/b>","maneuver":"keep-right","polyline":{"points":"uzssBuzc|LrQlFd@Nd@N|XrInBn@zBp@vQpF`F|AjVpH~PfFzAh@"},"start_location":{"lat":19.1122651,"lng":72.93371189999999},"travel_mode":"DRIVING"},{"distance":{"text":"0.9 km","value":921},"duration":{"text":"1 min","value":54},"end_location":{"lat":19.0849757,"lng":72.9217895},"html_instructions":"Continue straight to stay on <b>NH 3<\/b>","maneuver":"straight","polyline":{"points":"i~osB}gb|LZJ|NlEXHTHn@R|@VvAb@tC~@b@NTHh@TB?TJNHZNTL`@T`@Vr@f@d@^`E~C"},"start_location":{"lat":19.0923682,"lng":72.9255933},"travel_mode":"DRIVING"},{"distance":{"text":"0.1 km","value":132},"duration":{"text":"1 min","value":18},"end_location":{"lat":19.0842303,"lng":72.92085449999999},"html_instructions":"Take the exit on the <b>right<\/b> toward <b>Link Rd<\/b>","maneuver":"ramp-right","polyline":{"points":"cpnsBepa|LBV@@@@rBlBDDBDDF@FFT"},"start_location":{"lat":19.0849757,"lng":72.9217895},"travel_mode":"DRIVING"},{"distance":{"text":"0.3 km","value":275},"duration":{"text":"1 min","value":47},"end_location":{"lat":19.0862782,"lng":72.9194201},"html_instructions":"Continue onto <b>Link Rd<\/b><div style=\"font-size:0.9em\">Pass by A 3 (on the left)<\/div>","polyline":{"points":"mknsBija|LIRoDtB{BpAcB`A
01-05 17:01:09.117 3736-3820/in.test D/xxx: distance: {"text":"15.8 km","value":15818}
01-05 17:01:09.117 3736-3820/in.test D/SEE THE DIST :: 15.8 km15818

谢谢Kenny!


0

我看到有几个人已经正确回答了,但是看看这个答案。非常有用的API,可以使用Google地图方向API。 Google Maps Direction Api usage


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接