代码之家  ›  专栏  ›  技术社区  ›  MK-DK

在谷歌地图中设置标签

  •  0
  • MK-DK  · 技术社区  · 7 年前

    我做了一个谷歌地图有x个不同的引脚。当我将鼠标悬停在一个pin上时,我可以看到html代码:

    ['Company a<br>\
    Address x, Dk-2750 <br>\
    <a href="#">Show way</a>
    

    我已经尝试设置标题和标签,所以我可以选择文本应该是什么时候悬停在一个引脚。有谁知道我怎么能在一个别针上钉上一个标签?

    <script>
      function initMap() {
        var center = {lat: 56.2639, lng: 9.5018};
        var locations = [
          ['Company a<br>\
          Address x, Dk-2750 <br>\
         <a href="#" alt>Show way</a>',   55.730097, 12.375905],
    
          ['Company b<br>\
          Address y, Dk-6600<br>\
         <a href="#">Show way</a>', 55.769726, 12.497519],
    
          ['Company c<br>\
          Address z, Dk-6950<br>\
          <a href="#">Show way</a>', 56.110692, 8.322713],
        ];
      var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 7,
          center: center
        });
      var infowindow =  new google.maps.InfoWindow({});
      var marker, count;
      for (count = 0; count < locations.length; count++) {
          marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[count][1], locations[count][2]),
            map: map,
            title: locations[count][0]
          });
      google.maps.event.addListener(marker, 'click', (function (marker, count) {
            return function () {
              infowindow.setContent(locations[count][0]);
              infowindow.open(map, marker);
            }
          })(marker, count));
        }
      }
    </script>
    

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  0
  •   Keyyubi    7 年前

    我想你应该在google.maps.event下面再添加一个事件列表器… 你可以试试 google.maps.events.addListener(marker,'hover',function(..){...}) 或者像这样的。就像我悲伤,我只是猜测:)