android - 使用纬度和经度信息创建 Google 位置 URL

标签 android location linkify

enter image description here enter image description here

我有一个代码,用于检索纬度和经度信息。我有兴趣在 map 上显示该信息。我想为谷歌地图创建一个链接,其中包含检索到的“经度”和“纬度”信息。我正在使用Linkify为此,如下:

**** Java 代码**:

 String text = "maps.google.com/?q=latitude,longitude";
 TextView label = (TextView)findViewById(R.id.textView);
 label.setText(text);
 Pattern pattern = Pattern.compile("maps.google.com");
 Linkify.addLinks(label, pattern, "http://");

但是这段代码不起作用。有人可以帮我写代码吗? 我收到类似以下内容的信息。我的经度和纬度未与网址的其余部分链接。

最佳答案

您可以使用下面的代码来显示 map

    String url = "geo:" +  sLatitude + "," + sLongitude +"?z=22&q="+sLatitude + "," + sLongitude;
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);

上面的代码显示了使用手机中安装的谷歌地图应用程序的 map ,它还标记了缩放级别为 22 的位置。无需谷歌地图 api key

希望这会有所帮助......

关于android - 使用纬度和经度信息创建 Google 位置 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15060867/

相关文章:

android - 无法导入 android.text.util.Regex?它在哪里?

android - Linkify Android 转换问题

android - 如何在 Windows Terminal 中查看 Android 登录?

android - 从获取的坐标中获取位置名称

php - <script> document.location.href ='' ;</script> & 转到页面相关问题

android - LocationServices.SettingsApi 已弃用

android - 在 ListView 的 ArrayAdapter 中使用 Linkify 导致 RuntimeException

android - Android NDK : Nothing being drawn 中的 OpenGL ES 2.0

android - DialogFragment 在其 show() 之后调用 onCreateDialog()

php - 无法使用php+android从mysql检索数据