【问题标题】:How to display markers in groundOverlay map?如何在groundOverlay地图中显示标记?
【发布时间】:2015-05-27 13:22:23
【问题描述】:

我可以设法在地图上显示我的图像叠加层。但是出现了一个新问题 - 我无法在其上添加标记。我用谷歌搜索了一段时间,但没有运气。试图搜索和模仿文档中的示例,但似乎没有任何问题。

这是我的代码:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
    function initialize() {
      var newark = new google.maps.LatLng(xx.xxxxx,xx.xxxxx);
      var imageBounds = new google.maps.LatLngBounds(
          new google.maps.LatLng(xx.xxxxx,xx.xxxxx),//SW
          new google.maps.LatLng(xx.xxxxx,xx.xxxxx)//NE
        );

      var mapOptions = {
        zoom: 20,
        center: newark,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }

      var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

      var oldmap = new google.maps.GroundOverlay(
          'images/floor_plan_trans_rotated.gif',
          imageBounds);
      oldmap.setMap(map);
    }

    /*markers*/
      var contentString = '<div id="content">'+
          '<div id="siteNotice">'+
          '</div>'+
          '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
          '<div id="bodyContent">'+
          '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
          'sandstone rock formation in the southern part of the '+
          'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+
          'south west of the nearest large town, Alice Springs; 450&#160;km '+

</p>'+
      '<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'http://en.wikipedia.org/w/index.php?title=Uluru</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>'+
      '</div>';

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

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

/*markers*/
google.maps.event.addDomListener(window, 'load', initialize);
    </script>
<div id="map-canvas"></div>

对于上面的代码。除非我删除 /markers/ 之间的那些线,否则地图不会显示。

请提出建议。 问候,

【问题讨论】:

    标签: api google-maps overlay google-maps-markers


    【解决方案1】:

    在这段代码的第一个 /markers/ 上方没有额外的 } 吗?或者我只是困了....

    我正在做类似的事情,它正在工作,groundOverlay 和标记在同一张地图上

    【讨论】:

    • 这也许值得评论,但不是答案。
    • 要批评或要求 OP 澄清,请添加评论(不是答案:))。
    【解决方案2】:

    你的代码中有一些东西放错地方了。

    1. 前缺少单引号 (')
    2. 提前关闭初始化函数大括号 (})

    休息一切似乎都很好。我更正了这些,这是完整的代码。

    <script>
        function initialize() {
            var newark = new google.maps.LatLng(xx.xxxxx,xx.xxxxx);
            var imageBounds = new google.maps.LatLngBounds(
                new google.maps.LatLng(xx.xxxxx,xx.xxxxx),//SW
                new google.maps.LatLng(xx.xxxxx,xx.xxxxx)//NE
            );
    
            var mapOptions = {
                zoom: 18,
                center: newark,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }
    
            var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
    
            var oldmap = new google.maps.GroundOverlay(
                'images/floor_plan_trans_rotated.gif', imageBounds);
            oldmap.setMap(map);
    
            /*markers*/
            var contentString = '<div id="content">'+
                '<div id="siteNotice">'+
                '</div>'+
                '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
                '<div id="bodyContent">'+
                '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
                'sandstone rock formation in the southern part of the '+
                'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+
                'south west of the nearest large town, Alice Springs; 450&#160;km '+
                '</p>'+
                '<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
                'http://en.wikipedia.org/w/index.php?title=Uluru</a> '+
                '(last visited June 22, 2009).</p>'+
                '</div>'+
                '</div>';
    
            var infowindow = new google.maps.InfoWindow({
                content: contentString,
                maxWidth: 400
            });
    
            var marker = new google.maps.Marker({
                position: newark,
                map: map,
                title: 'Uluru (Ayers Rock)'
            });
    
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(map,marker);
            });
        }
    
        /*markers*/
        google.maps.event.addDomListener(window, 'load', initialize);
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      • 2012-03-20
      • 2017-10-25
      • 1970-01-01
      • 2017-05-24
      • 2017-01-24
      相关资源
      最近更新 更多