如何从api响应方向获取行车路线?

时间:2012-01-16 09:48:02

标签: android google-maps directions map-directions

我想在android中的谷歌地图上画一条路线。 为此,我使用谷歌方向api获得路线点http://code.google.com/intl/de-DE/apis/maps/documentation/directions/

现在我想知道如何获得方向箭头(如:向左转,......) 来自这个api的json回应。

回复如下:

    {
 "routes" : [
  {
     "bounds" : {
        "northeast" : {
           "lat" : 48.306950,
           "lng" : 14.304310
        },
        "southwest" : {
           "lat" : 48.163440,
           "lng" : 14.033580
        }
     },
     "copyrights" : "Map data ©2012 GeoBasis-DE/BKG (©2009), Google",
     "legs" : [
        {
           "distance" : {
              "text" : "34.6 km",
              "value" : 34554
           },
           "duration" : {
              "text" : "31 mins",
              "value" : 1866
           },
           "end_address" : "Linz, Austria",
           "end_location" : {
              "lat" : 48.306950,
              "lng" : 14.285860
           },
           "start_address" : "Wels, Austria",
           "start_location" : {
              "lat" : 48.16545000000001,
              "lng" : 14.036620
           },
           "steps" : [
              {
                 "distance" : {
                    "text" : "0.3 km",
                    "value" : 252
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 28
                 },
                 "end_location" : {
                    "lat" : 48.164110,
                    "lng" : 14.033890
                 },
                 "html_instructions" : "Head \u003cb\u003esouthwest\u003c/b\u003e on \u003cb\u003eHans-Sachs-Straße\u003c/b\u003e toward \u003cb\u003eGemeindestr.\u003c/b\u003e",
                 "polyline" : {
                    "points" : "ai~dH{ottAHHHNN`@jBjFzBxF"
                 },
                 "start_location" : {
                    "lat" : 48.16545000000001,
                    "lng" : 14.036620
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "0.1 km",
                    "value" : 149
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 48
                 },
                 "end_location" : {
                    "lat" : 48.163440,
                    "lng" : 14.03470
                 },
                 "html_instructions" : "At the roundabout, take the \u003cb\u003e3rd\u003c/b\u003e exit onto \u003cb\u003eMagazinstr./B1\u003c/b\u003e",
                 "polyline" : {
                    "points" : "u`~dHy~stAEBCDAHAH@H@HDHB@B@D?DABADGBG@G?GAIAGvAkCP_@"
                 },
                 "start_location" : {
                    "lat" : 48.164110,
                    "lng" : 14.033890
                 },
                 "travel_mode" : "DRIVING"
              },
    .
    .
    .

这应该是可能的,因为谷歌地图:http://maps.google.com/使用相同的方向api(据我所知)并且它在路线描述的每个条目的左侧绘制这样的箭头(只计算任何路线)看看我的意思。)

我非常感谢各种帮助

2 个答案:

答案 0 :(得分:0)

看看我的answer。这将为您提供另一种获取方向指示的方法 使用KML文件

答案 1 :(得分:0)

这就是我正在使用的,

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?saddr="+latitude_cur+","+longitude_cur+"&daddr="+latitude+","+longitude));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_LAUNCHER );     
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);