Google Maps marque comme un lien

J'utilise Google Maps pour mon site Web et je me déplace comment puis-je utiliser les marqueurs comme liens? Je veux dire quand je clique sur un marqueur pour ouvrir un lien particulier.

Merci d'avance!

C'est vraiment très simple à faire. Il suffit de joindre un gestionnaire d'événements à votre marqueur, puis lancez le lien en configurant window.location.href sur votre URL. Consultez les exemples suivants, ce qui, je pense, devrait être explicite par lui-même:

Utilisation de l' API v3 :

 <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>Google Maps Marker as a Link</title> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> </head> <body> <div id="map" style="width: 500px; height: 400px;"></div> <script type="text/javascript"> var map = new google.maps.Map(document.getElementById('map'), { zoom: 2, center: new google.maps.LatLng(35.55, -25.75), mapTypeId: google.maps.MapTypeId.ROADMAP }); var marker = new google.maps.Marker({ position: map.getCenter(), url: 'http://www.google.com/', map: map }); google.maps.event.addListener(marker, 'click', function() { window.location.href = marker.url; }); </script> </body> </html> 

Utilisation de l' API V2 :

 <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>Google Maps Marker as a Link</title> <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false" type="text/javascript"></script> </head> <body onunload="GUnload()"> <div id="map" style="width: 500px; height: 400px;"></div> <script type="text/javascript"> var map = new GMap2(document.getElementById("map")); var centerPoint = new GLatLng(35.55, -25.75); map.setCenter(centerPoint, 2); var marker = new GMarker(map.getCenter()); marker.url = 'http://www.google.com/'; map.addOverlay(marker); GEvent.addListener(marker, 'click', function() { window.location.href = marker.url; }); </script> </body> </html> 

Les exemples ci-dessus ajouteront un marqueur quelque part dans l'océan atlantique. Lorsque vous cliquez dessus, vous serez transmis à un moteur de recherche populaire.

Pour que cela s'ouvre dans un nouvel onglet, ajoutez le suivant immédiatement après "window.location.href = marker.url;":

 window.open(this.url, '_blank'); 

Donc vous auriez:

 google.maps.event.addListener(marker, 'click', function() { window.location.href = marker.url; window.open(this.url, '_blank'); });