Android 如何从我的应用程序直接使用谷歌地图导航
你好 我正在尝试使用谷歌地图将我的应用程序用户导航到某个地址/位置。根据我目前在网上的发现,我尝试了以下方法:Android 如何从我的应用程序直接使用谷歌地图导航,android,google-maps,Android,Google Maps,你好 我正在尝试使用谷歌地图将我的应用程序用户导航到某个地址/位置。根据我目前在网上的发现,我尝试了以下方法: Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?saddr=-36.181,27.949&daddr=-36.174732,27.949770"));
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=-36.181,27.949&daddr=-36.174732,27.949770"));
startActivity(intent);
现在这一切都很好,它打开了谷歌地图,但在我真正进入导航之前,它问了我很多事情
- 1:它首先让我选择一次旅行
- 他说:然后它会告诉我这趟旅行
- 3:然后我必须单击小箭头(导航按钮)
// try this way,hope this will help you to solve your problem.
String uri = "http://maps.google.com/maps?f=d&hl=es&saddr=-36.181,27.949&daddr=-36.174732,27.949770";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
String urlAddress = "http://maps.google.com/maps?q="+ lat + ","+ lng + "("
+ your_location_name + ")&iwloc=A&hl=es";
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(urlAddress));
startActivity(intent);
这将打开给定有效lat、lng值的谷歌地图,并将显示您的位置名称作为地名。尝试此方法
String urlAddress = "http://maps.google.com/maps?q="+ lat + ","+ lng + "("
+ your_location_name + ")&iwloc=A&hl=es";
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(urlAddress));
startActivity(intent);
String uri = "google.navigation:q=%f, %f";
Intent navIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String .format(Locale.US, uri, customerDropOffLatLng.latitude, customerDropOffLatLng.longitude)));
navIntent.setPackage("com.google.android.apps.maps");
startActivity(navIntent);
这将在给定的有效lat上打开google地图,lng值并将显示您的位置名称作为地名。生成的结果与我的初始结果相同。当您尝试通过默认的google map应用程序显示路线时,我们将执行his步骤not are,如果您不希望执行此类步骤,则必须开发自定义根实现代码。生成的结果与我的初始结果相同第一,当您尝试通过默认的谷歌地图应用程序显示路线时,我们会按照his步骤进行操作,如果您不希望执行此类步骤,那么您必须开发自定义的根实现代码。请您澄清一下,您的地址是目的地地址吗?日志和lat将显示您当前的位置?这将在给定的有效lat、lng值上打开谷歌地图,并将显示您的位置名称作为地名。但这不会自动启动导航?@Zapnologica抱歉,我没有理解。请看一下,你能澄清一下,你的地址是目的地吗?日志和lat将显示您当前的位置?这将在给定的有效lat、lng值上打开谷歌地图,并将显示您的位置名称作为地名。但这不会自动启动导航?@Zapnologica抱歉,我没有理解。请看一看这个欢迎来到SO。请避免只回答代码问题;提供一些上下文/解释。见欢迎来到SO。请避免只回答代码问题;提供一些上下文/解释。看见
String uri = "google.navigation:q=%f, %f";
Intent navIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String .format(Locale.US, uri, customerDropOffLatLng.latitude, customerDropOffLatLng.longitude)));
navIntent.setPackage("com.google.android.apps.maps");
startActivity(navIntent);