Question

Is there a way to hyperlink a custom marker on google maps marker to its coordinates on Google Maps itself? In this case link to LatLng. Also, is there a way to open it in a new tab using target="_blank" or javascript with the same effect?

      function initialize() {
            var mapOptions = {
                zoom: 14,
                center: new google.maps.LatLng(-29.528000, 31.194881)
            }
            var map = new google.maps.Map(document.getElementById('ContactMap'),
                                          mapOptions);

            var image = '/Assets/Images/Pages/Marker.png';
            var myLatLng = new google.maps.LatLng(-29.528000, 31.194881);
            var beachMarker = new google.maps.Marker({
                position: myLatLng,
                map: map,
                icon: image
            });
        }

        google.maps.event.addDomListener(window, 'load', initialize);
Was it helpful?

Solution

A real hyperlink is not possible, but of course you may set up a click-listener to achieve a similar behaviour:

        google.maps.event.addListener(beachMarker,'click',function(){
          window.open('https://maps.google.com/maps?q=' +
                       this.getPosition().toUrlValue() +
                       '&z='+this.getMap().getZoom(),'google');
        });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top