您好我使用以下代码显示用户在当前位置和他的汽车位置之间的方向。
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应用程序的导航转向?。
答案 0 :(得分:8)
Ey,我刚遇到这个问题,您可以通过更改您在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();
然后,如果您有多个应用来处理导航流程并且您想直接进行Google导航,那么您还可以包含对活动进行“setClassName”调用的行:
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
希望它有所帮助;)