如何在地图中的标记中添加链接?

时间:2015-11-20 10:36:14

标签: jsp google-maps-api-3 geolocation google-maps-markers geocoding

我想在地图中添加指向标记的链接

这是我的代码

 function findAddress(getLati,getLongi) {
       var latlng = new google.maps.LatLng(getLati, getLongi);
    geocoder.geocode( { 'latLng': latlng}, function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) 

                    { // and, if everything is ok                     
                     var addrLocation = results[0].formatted_address;                   
                     document.getElementById('lat').value = getLati;
                     document.getElementById('lng').value = getLongi;
                     var addrMarker = new google.maps.Marker({
                                                             position: latlng,
                                                             map: map,
                                                             title: results[0].formatted_address
                                                             });

                     google.maps.event.addListener(addrMarker, 'click', function() {                                            
                                                   var infowindow = new google.maps.InfoWindow({                                                                                            });
                                                   infowindow.open(map,addrMarker);
                                                   infos.push(infowindow);
                                                   });                     
                    var infowindow = new google.maps.InfoWindow({
                                   content: '<font style="color:#000;">' + results[0].formatted_address + '</font>'
                                                   });
                     infowindow.open(map,addrMarker);
                     infos.push(infowindow);
                     }
                     else
                     {
                     alert('Geocode was not successful for the following reason: ' + status);
                     }
                     });
}

我想添加重定向标记的链接。 谁能帮我这个??另外,我想在地图

中添加标记链接

1 个答案:

答案 0 :(得分:0)

您可以在标记中添加信息窗口。当用户点击您的标记时,将打开一个信息窗口,您可以添加您希望用户前往的链接。

 var contentString = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
          '<p>Attribution:

      Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'https://en.wikipedia.org/w/index.php?title=Uluru</a> '+
      '</div>'+
      '</div>';

  var infowindow = new google.maps.InfoWindow({
    content: contentString
  });

  var marker = new google.maps.Marker({
    position: uluru,
    map: map,
    title: 'Uluru (Ayers Rock)'
  });
  marker.addListener('click', function() {
    infowindow.open(map, marker);
  });
}