android - 打开 map 以通过 intent-Android 显示当前位置的方向

标签 android google-maps android-studio android-intent

我的 android 应用程序中有很多经纬度。我想知道如何通过 Intent 打开选择器或谷歌地图应用程序并显示从当前位置到该纬度和经度的方向。就像我有 lat=28.605989,lon=77.372970 并且我当前的位置在某个地方所以当我点击按钮时我的应用程序这些经纬度通过 Intent 传递,并将显示从我当前位置到这些经纬度的方向。谢谢。

最佳答案

要将用户长时间导航到目的地,我们可以使用类似这样的东西

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
Uri.parse("http://maps.google.com/maps?daddr=28.605989,77.372970"));
startActivity(intent);

在这里。我们只传递目的地经纬度 daddr=28.605989,77.372970,因此默认情况下,您的当前位置将是源位置。

使用您的网址添加额外信息。

String my_data= String.format(Locale.ENGLISH, "http://maps.google.com/maps?daddr=20.5666,45.345(My Destination Place)");

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(my_data));
intent.setPackage("com.google.android.apps.maps");
startActivity(intent);

关于android - 打开 map 以通过 intent-Android 显示当前位置的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52310436/

相关文章:

android - 如何在多风格应用程序中添加多个 Google Maps API 配置

java - 从 ListView 中删除行的动画

android multidex 实现

android - 如何按名称从 res/raw 读取文件

javascript - 仅在 Google map (v3) 中单击折线时触发一次单击事件

android - 检查屏幕位置改变了多少appium android

javascript - 谷歌地图中热图的中值缩小

java - Android - 适配器 NullPointerException

java - (Android Studio Java) FAB OnClick 警报对话框使应用程序崩溃

android - Adapter中如何将startActivity添加到OnClickListener中?