Api 如何在地面覆盖图中显示标记?

Api 如何在地面覆盖图中显示标记?,api,google-maps,overlay,google-maps-markers,Api,Google Maps,Overlay,Google Maps Markers,我可以设法在地图上显示我的图像叠加。但是出现了一个新问题——我不能在上面添加标记。我在谷歌上搜索了一段时间,但运气不好。试图在文档中搜索和模仿示例,但似乎没有任何结果 这是我的密码: <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> <script> function initialize() { var newa

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

这是我的密码:

<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>

函数初始化(){
var newark=newgoogle.maps.LatLng(xx.xxxxx,xx.xxxxx);
var imageBounds=new google.maps.LatLngBounds(
新的google.maps.LatLng(xx.xxxxx,xx.xxxxx),//SW
新的google.maps.LatLng(xx.xxxxx,xx.xxxxx)//NE
);
变量映射选项={
缩放:20,
中心:纽瓦克,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var oldmap=new google.maps.GroundOverlay(
'images/floor\u plan\u trans\u rotated.gif',
图像边界);
oldmap.setMap(map);
}
/*标记*/
var contentString=''+
''+
''+
“乌鲁鲁”+
''+
“Uluru,也称为艾尔斯岩,是一个大型的”+
“南部的砂岩岩层”+
“北领地,澳大利亚中部。它位于335和160之间;公里(208英里)+
“最近的大城镇爱丽丝·斯普林斯西南部;450 公里+

'+ “归属:乌卢鲁,”+ (上次访问日期为2009年6月22日)。

'+ ''+ ''; var infowindow=new google.maps.infowindow({ content:contentString, 最大宽度:400 }); var marker=new google.maps.marker({ 职位:纽瓦克, 地图:地图, 标题:“乌卢鲁(艾尔斯岩)” }); google.maps.event.addListener(标记'click',函数(){ 信息窗口。打开(地图、标记); }); } /*标记*/ google.maps.event.addDomListener(窗口“加载”,初始化);
对于上面的代码。除非删除/markers/之间的线,否则地图将不会显示

请建议。
请注意,

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


我正在做一些类似的事情,它正在工作,在同一张地图上使用groundOverlay和marker

代码中有两件东西放错了位置

  • 前面缺少单引号(')

  • 以较早的方式(})关闭初始化函数
  • 一切似乎都很好。我更正了这些,这是完整的代码

    <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>
    
    
    函数初始化(){
    var newark=newgoogle.maps.LatLng(xx.xxxxx,xx.xxxxx);
    var imageBounds=new google.maps.LatLngBounds(
    新的google.maps.LatLng(xx.xxxxx,xx.xxxxx),//SW
    新的google.maps.LatLng(xx.xxxxx,xx.xxxxx)//NE
    );
    变量映射选项={
    缩放:18,
    中心:纽瓦克,
    mapTypeId:google.maps.mapTypeId.ROADMAP
    }
    var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
    var oldmap=new google.maps.GroundOverlay(
    “images/floor\u plan\u trans\u rotated.gif”,imageBounds);
    oldmap.setMap(map);
    /*标记*/
    var contentString=''+
    ''+
    ''+
    “乌鲁鲁”+
    ''+
    “Uluru,也称为艾尔斯岩,是一个大型的”+
    “南部的砂岩岩层”+
    “澳大利亚中部的北领地。它位于335公里(208英里)处”+
    “最近的大城镇艾丽斯·斯普林斯西南部;450 ;公里”+
    “

    ”+ “归属:乌卢鲁,”+ (上次访问日期为2009年6月22日)。

    '+ ''+ ''; var infowindow=new google.maps.infowindow({ content:contentString, 最大宽度:400 }); var marker=new google.maps.marker({ 职位:纽瓦克, 地图:地图, 标题:“乌卢鲁(艾尔斯岩)” }); google.maps.event.addListener(标记'click',函数(){ 信息窗口。打开(地图、标记); }); } /*标记*/ google.maps.event.addDomListener(窗口“加载”,初始化);
    这可能值得评论,但不是答案。若要评论或要求OP澄清,请添加评论(不是答案:)。