Zack
Zack

Reputation: 5148

How to put a link in a Google map marker's snippet

I'm trying to link a website and (hopefully) a phone number into a snippet of a map marker that I am creating on my map. Is there anyway to do this? If not, what is another way I could possibly display something above the clicked marker that contains a clickable website and a clickable phone number. I was thinking an Alert Dialog but I do not know how to set up onClickListeners for dynamically made map markers.

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);
}

Upvotes: 1

Views: 1771

Answers (1)

tyczj
tyczj

Reputation: 74066

If you want the link to be clickable, this will not work

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.

you can however show a dialog with the information if you like when the marker is clicked

Upvotes: 4

Related Questions