【问题标题】:How do I show a marker in Maps launched by geo URI Intent?如何在地理 URI Intent 启动的地图中显示标记?
【发布时间】:2011-04-28 18:06:09
【问题描述】:

我有一个应用程序,我想通过启动带有特定地理坐标的 Google 地图来显示不同的位置(一次一个,由用户输入选择)。

我目前正在使用这个(当然是真正的纬度和经度值):

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?z=17"));
startActivity(intent);

这正是我想要的,只是它没有为指定点显示任何指示器或标记。它只以它所在的位置为中心。

有没有什么方法可以在不使用 MapView 的情况下获取标记或其他内容?

【问题讨论】:

  • 标签已停止在最近的地图更新中显示.. 怎么办?

标签: android google-maps android-intent android-maps


【解决方案1】:

试试这个:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
startActivity(intent);

如果你不想要标签,你可以省略 (Label+Name),它会根据最近的街道或其他它认为相关的东西随机选择一个。

【讨论】:

  • 实现此 URI 后,我在设置缩放时遇到问题。现在好像已经过时了
  • @mmm...:您需要将 ?z 更改为 &z。你只能拥有一个?在一个uri。不好:geo:N,M?z=10?q=N,M(Place) 好:geo:N,M?z=10&q=N,M(Place)
  • 缩放被忽略,因为这是一个简单的查询而不是地理意图。这里发生的实际上是一个简单的查询发送给谷歌,然后服务器响应一个与之对应的“搜索结果”。您可以尝试在 maps.google.com 上搜索 ,(Label+Name) 并获得相同的结果
  • 使用这个(或此处涉及标记查询的任何其他方法)完全忽略了geo: 部分中的地理点,lke robpvn 指出。在某些情况下,使用纬度/经度查询将失败,然后您只会得到“无结果”吐司,而不是回退到地理点。对于任何类型的 GIS 应用程序都不是很有用。
  • 这不再起作用..标签不显示
【解决方案2】:

使用 Intent 启动 Google 地图还有更多选项...

   Double myLatitude = 44.433106;
   Double myLongitude = 26.103687;
   String labelLocation = "Jorgesys @ Bucharest";

1)

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<" + myLatitude  + ">,<" + myLongitude + ">?q=<" + myLatitude  + ">,<" + myLongitude + ">(" + labelLocation + ")"));
    startActivity(intent);

2)

String urlAddress = "http://maps.google.com/maps?q="+ myLatitude  +"," + myLongitude +"("+ labelLocation + ")&iwloc=A&hl=es";
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
    startActivity(intent);

3)

   String urlAddress = "http://maps.googleapis.com/maps/api/streetview?size=500x500&location=" + myLatitude  + "," + myLongitude + "&fov=90&heading=235&pitch=10&sensor=false";
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlAddress));
        startActivity(intent);

【讨论】:

  • 看起来像 2) "&iwloc=A&hl=es" 并不是真正需要的
  • "iwloc" 代表信息窗口位置,"hl" 代表语言,如果您不设置此值,则应用默认值。 =)
  • 你在第二条路上错过了)
  • 起来!第二和第三个选项!谢谢我都修好了! ᕦ ´• ᴥ •` ᕥ @Baras
【解决方案3】:

接受的答案是正确的,除非您的标签中包含与号 (&)。

看着A Uniform Resource Identifier for Geographic Locations ('geo' URI)

第 5.1 节规定:

如果最终的 URI 包含一个“查询”组件,则添加 组件分隔符“?”到结果的末尾,然后是 编码查询字符串。

不幸的是,这样做也会避开我们不想要的“=”。

我们应该这样做:

String label = "Cinnamon & Toast";
String uriBegin = "geo:12,34";
String query = "12,34(" + label + ")";
String encodedQuery = Uri.encode(query);
String uriString = uriBegin + "?q=" + encodedQuery;
Uri uri = Uri.parse(uriString);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);

【讨论】:

【解决方案4】:

这个字符串很适合我:

String geoUriString="geo:"+lat+","+lon+"?q=("+head+")@"+lat+","+lon;
Uri geoUri = Uri.parse(geoUriString);
Log.e(TAG, "String: "+geoUriString);
Intent mapCall  = new Intent(Intent.ACTION_VIEW, geoUri);
startActivity(mapCall);

【讨论】:

    【解决方案5】:

    尝试将 (LocationMarkerName) 附加到 geo: uri。例如,“geo:,?z=17(LocationMarkerName)”

    在 Android 上的 Google 地图中搜索 23.0980,30.6797 (NamedMarker),它似乎将地图居中并在该位置放置一个名为 NamedMarker 的标记。

    【讨论】:

      【解决方案6】:

      我刚刚确认来自@Kenton Price 的以下 sn-p 仍然适用于 Android 4.4 (KitKat):

      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:<lat>,<long>?q=<lat>,<long>(Label+Name)"));
      startActivity(intent);
      

      【讨论】:

        【解决方案7】:

        我只使用带有 MapView 的 Overlays 在地图上绘制标记。如果您的视图正在显示您的地图,则可以简单地在屏幕中心绘制标记,就像在视图上绘制任何图像一样。

        但是,标记不会链接到实际的地图坐标,但如果它只是一个静态视图,那么可能会这样做。

        【讨论】:

          猜你喜欢
          • 2018-12-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-04-26
          • 1970-01-01
          • 2017-01-10
          • 1970-01-01
          相关资源
          最近更新 更多