dongzaizai2015 2013-07-26 07:34
浏览 53
已采纳

谷歌地图与自定义信息窗集成多个标记

I have used coding for multiple markers and I need to customize the info window which is now displaying the default one. i need to custom the window with the background image and with with link

      <script type="text/javascript"> 
       var locations = [['chennai', 13.0810, 80.2740, 4],
        ['madurai', 9.9300, 78.1200, 5],
        ['coimbatore', 11.0183, 76.9725, 3],
         ['Trichy', 10.8100, 76.9725, 2],
         ['vellore', 12.9202, 79.1333, 1]];

      var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 10,
      center: new google.maps.LatLng(13.0810, 80.2740),
      mapTypeId: google.maps.MapTypeId.ROADMAP
   });

   var infowindow = new google.maps.InfoWindow();

   var marker, i;
var icon='images/';
for (i = 0; i < locations.length; i++) {  
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    icon: icon + 'pin.png',
    map: map
  });

  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][0]);
      infowindow.open(map, marker);
    }
    })(marker, i));
   }
 </script>
  • 写回答

1条回答 默认 最新

  • dth96108 2013-07-26 08:28
    关注

    You can place anything you like HTML wise into the info window that you create with this call.

    infowindow.setContent(locations[i][0]);
    

    So you can do this for example

    var info = '<div class="mybackground">' +
    '<div>Hello World</div>
    '<div><a href="url">Link</a></div>
    '<div>';
    infowindow.setContent(info);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助