【问题标题】:how to send location coordinates from an app to any map app?如何将位置坐标从应用程序发送到任何地图应用程序?
【发布时间】:2018-02-10 03:30:02
【问题描述】:

我已经尝试发送到谷歌地图,但我希望我的应用程序询问您要在哪个应用程序中打开,或者只显示我的手机地图应用程序的选项,就像我们点击某个 URL 时一样,它会显示所有在我们的手机浏览器,让我们选择。 任何帮助将不胜感激。

【问题讨论】:

标签: android


【解决方案1】:

好问题:您可以使用 ACTION_VIEW 发送 Intent,其中元数据是以架构 geo 开头的字符串:

这里是这样描述的: https://developer.android.com/guide/components/intents-common.html#ViewMap

而且很简单:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:47.6,-122.3?z=11");
startActivity(intent);

在我提供的链接中有更多选项可以发送更多参数。

【讨论】:

    【解决方案2】:

    试试这个代码:

        Uri geoLocation = Uri.parse("geo:" + model.getLocation_lat() + "," + model.getLocation_lng());
    
    // you can use this if you have other information like address of place
        Uri geoLocation = Uri.parse("geo:" + model.getLocation_lat() + "," + model.getLocation_lng()+ "?q=" + model.getAddress());    
    
        Intent intent = new Intent(Intent.ACTION_VIEW, geoLocation);
                startActivity(Intent.createChooser(intent, "choose an application "));
    

    这就是你所需要的。

    【讨论】:

      【解决方案3】:

      这将为您提供在浏览器或谷歌地图中打开的两个选项

                      Intent intent = new Intent(Intent.ACTION_VIEW);
                      intent.setData(Uri.parse("http://maps.google.co.in/maps?q="+your address);
                      if (intent.resolveActivity(getPackageManager()) != null) 
                      {
                          startActivity(intent);
                      }
      

      【讨论】:

        猜你喜欢
        • 2015-03-06
        • 1970-01-01
        • 2020-10-16
        • 2017-11-24
        • 1970-01-01
        • 2017-10-22
        • 2014-02-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多