【问题标题】:Open navigation activity directly of deafault android map programmatically - Android以编程方式直接打开默认android地图的导航活动 - Android
【发布时间】:2014-07-27 17:25:17
【问题描述】:

您好,我正在使用以下代码显示用户当前位置和汽车位置之间的方向。

 String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?saddr=%f,%f(%s)&daddr=%f,%f (%s)", curLat, curLong, "Your location", carLat, carLong, "Your vehicle location");
 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
 intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
 startActivity(intent);

这很好,但我需要在进入导航活动之前按下开始导航。我想要的是我需要直接进入导航活动而不按开始导航按钮。

如下所示。左边的图像是我首先得到的。单击底部的开始导航按钮后,我会被带到轮流导航(右图)。是否可以直接转到默认android应用程序的轮流导航?。

【问题讨论】:

    标签: android gps geolocation android-location android-navigation


    【解决方案1】:

    嗯,我刚刚遇到了这个问题,您可以通过更改您在 Intent 上发送的 URI 来避免“按钮单击”操作。

    尝试这样做:

    LatLng destiny; // Your destiny LatLng object 
    String uri = "google.navigation:q=%f, %f";
    Intent navIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String
                .format(Locale.US, uri, destiny.latitude, destiny.longitude)));
    if (canHandleIntent(this, navIntent))
        startActivity(navIntent);
    else
        Toast.makeText(this, "Please install Google Navigation",
            Toast.LENGTH_LONG).show();
    

    然后,如果您有多个应用程序来处理导航流程,并且您想直接使用谷歌导航,您还可以将带有“setClassName”调用的行包含到活动中:

     intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
    

    希望对你有帮助;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-06
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      • 1970-01-01
      相关资源
      最近更新 更多