Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link marker to url Google Maps [duplicate]

Simple question:

Im trying to link my marker to an external url on a Google Map (API v3). Can just use http://www.google.com as the link for now.

Javascript:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
    function initialize() {
        var myLatlng = new google.maps.LatLng(-30.021664, 30.901578);
      var mapOptions = {
        zoom: 15,
        center: myLatlng,
        scrollwheel: false,
        disableDefaultUI: true
      }
    var map = new google.maps.Map(document.getElementById('ContactMap'), mapOptions);
    var image = '/Assets/Images/Icons/MapMarker.png';

      var marker = new google.maps.Marker({
          position: myLatlng,
          map: map,
          animation: google.maps.Animation.DROP,
          icon: image,
          title: 'Perspex'
      });
    }
    google.maps.event.addDomListener(window, 'load', initialize);
</script>
like image 832
Dale Avatar asked Jan 30 '14 12:01

Dale


People also ask

How do I get rid of multiple markers on Google Maps?

To drop multiple pins on Google Maps, you'll need to customize your own map by using the Create Map option. This opens a custom map where you can drop as many pin icons as you like. You can create an itinerary for your next trip, so you never forget the locations you wanted to visit.


1 Answers

You need to add a google maps click event to the marker:

google.maps.event.addListener(marker, 'click', function () {
  window.location.href = 'http://www.google.com';
});

Do this immediately after defining marker.

like image 110
Andy Avatar answered Oct 13 '22 00:10

Andy