【问题标题】:How to put a link in a Google map marker's snippet如何在 Google 地图标记的片段中添加链接
【发布时间】:2013-07-17 16:41:42
【问题描述】:

我正在尝试将一个网站和(希望)一个电话号码链接到我在地图上创建的地图标记的 sn-p 中。有没有办法做到这一点?如果没有,我可能会在单击标记上方显示包含可点击网站和可点击电话号码的内容的另一种方式。我在考虑一个警报对话框,但我不知道如何为 动态 制作地图标记设置 onClickListeners。

public void addWayPointMarkers(LatLng point){
    MarkerOptions marker = new MarkerOptions();
    marker.title(name);
    marker.snippet(Html.fromHtml(address + "<br />" + phone + "<br />" + "<a href=\"" + website + "\">Website</a>"));       
    marker.position(point);

    map.addMarker(marker);
}

【问题讨论】:

  • 信息窗口中的链接将无法点击
  • 我的问题是是否有任何方法让它可点击。如果没有,您能建议另一种方法吗?
  • 我创建了一个 Marker ArrayList,每次单击一个标记时,我都会将该标记与 ArrayList 中的标记进行比较。需要做的就是让类实现 OnMarkerClickListener

标签: android google-maps-markers google-maps-android-api-2


【解决方案1】:

如果您希望链接可点击,这将不起作用

The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

但是,如果您愿意,可以在单击标记时显示包含信息的对话框

【讨论】:

  • 谢谢。您是否可以展示一个示例,说明如何使用我提供的代码显示对话框?
  • 它就像任何其他对话框一样,在开发者网站上查找对话框。您可能必须将信息存储在 HashMap 中,标记 id 作为键,信息作为内容
  • 如果我按照上面的代码动态创建标记,如何给它一个 ID?
  • map.addMarker(marker); 返回一个标记,从中获取 id
猜你喜欢
  • 1970-01-01
  • 2016-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-07
  • 1970-01-01
  • 2014-03-10
  • 2014-06-02
相关资源
最近更新 更多