如何在Google地图标记代码段中添加链接

时间:2013-07-17 16:41:43

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

我正在尝试将网站和(希望)电话号码链接到我在地图上创建的地图标记的片段中。反正有没有这样做?如果没有,我可能会在点击标记上方显示某些内容,包含可点击的网站和可点击的电话号码。我在想一个警报对话框,但我不知道如何为动态制作地图标记设置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);
}

1 个答案:

答案 0 :(得分:3)

如果您希望链接可以点击,则无法使用

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.

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