0

I have a map with several markers. I'd need to be able to display a link "Show directions" in the markers infowindow that would take the users to the maps.google.com and display the directions.

function setMarkers(map, locations) {

    for (var i = 0; i < locations.length; i++) {
        var shop = locations[i];
        var myLatLng = new google.maps.LatLng(shop[1], shop[2]);
        var nimi = shop[0];
        var osoite = shop[5];
        var puhelinnumero = shop[3];
        var verkkosivu = shop[4];
        var content = "<div class='content'><h3>"+nimi+"</h3><strong>Osoite:</strong> "+osoite+"<br /><strong>Puhelinnumero:</strong> "+puhelinnumero+"<br /><strong>Verkkosivu:</strong> <a href='"+verkkosivu+"' target='_blank'>"+verkkosivu+"</a><br /><br /><a href='http://maps.googleapis.com/maps/api/directions/json?origin=Vuonotie 19, 05200 Rajamäki&destination="+osoite+"'>Reittiohjeet</a></div>";
        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            title: shop[0]
        });

        var infowindow = new google.maps.InfoWindow()

        google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){ 
            return function() {
                infowindow.setContent(content);
                infowindow.open(map,marker);
            };
        })(marker,content,infowindow));  
    }
}

Is there a way to add something like http://maps.google.com/?from=address&to=address?

Wokki
  • 157
  • 2
  • 18

1 Answers1

2

Found a solution after a moment of googling. The issue was that I was googling for Google Developer and not just basic Google Maps.

It is apparently possible to have http://www.google.com/maps/dir/current+position/Address as a link, which will provide directions from user location to the selected address.

Wokki
  • 157
  • 2
  • 18