Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图中的中心标记_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 谷歌地图中的中心标记

Javascript 谷歌地图中的中心标记,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我正在尝试将谷歌地图放在iframe的中心。下面的代码是iframe的内容。 标记不在框架的中心 少了什么 <!DOCTYPE html> <html> <head> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100%

我正在尝试将谷歌地图放在iframe的中心。下面的代码是iframe的内容。 标记不在框架的中心

少了什么

<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas { height: 100% }
    </style>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=MYAPIKEY&sensor=false"></script>
    <script type="text/javascript">


function initialize() {
        var myLatlng = new google.maps.LatLng('<?php echo $this->uri->segment(5); ?>', '<?php echo $this->uri->segment(4); ?>');
          var myOptions = {
            zoom: 8,
                mapTypeControl: false,
                scaleControl: false,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          }
          var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

          var marker = new google.maps.Marker({
              position: myLatlng,
              map: map,
              title:"Hello World!"
          });

         }


        initialize();


    </script>
  </head>
  <body onload="initialize()">
    <div id="map_canvas" style="width:100%; height:100%"></div>
  </body>
</html>

html{高度:100%}
正文{高度:100%;边距:0;填充:0}
#地图画布{高度:100%}
函数初始化(){
var mylatng=new google.maps.LatLng(“”,”);
变量myOptions={
缩放:8,
mapTypeControl:false,
scaleControl:false,
中心:myLatlng,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
var map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“你好,世界!”
});
}
初始化();
更新

我想我已经解决了这个问题,为地图画布设置了一个固定的尺寸,而不是使用100%。 我现在工作得好多了。

你的代码对我有效->在
jsfiddle
中,映射在
iframe

我已经用一些虚拟数据替换了您的PHP代码。

您的代码对我有效->在
jsfiddle
中,映射在
iframe


我已经用一些伪数据替换了您的PHP代码。

是的,但问题是当我将其放在iframe中时,它不再居中。@Engineer。请创建一个答案,我会选择它作为最佳答案。是的,但问题是当我把它放在iframe中时,它不再居中。请创建一个答案,我将选择它作为最佳答案。