简体   繁体   English

Google地图中心位于左上角

[英]Google Map Centers at top left corner

I've been looking at many different examples, problems, and other things regarding this and I can't seem to find anything, so i'll finally ask a question. 我一直在寻找许多不同的例子,问题和其他相关的事情,我似乎找不到任何东西,所以我最后会问一个问题。

The map I have does not center the marker and doesn't even display it. 我所拥有的地图并不使标记居中,甚至不显示它。 The point it the very top left corner. 这点就在左上角。 See here: http://i.imgur.com/Cc1ZK.png 见: http//i.imgur.com/Cc1ZK.png

I have a tab system for contact information. 我有一个标签系统的联系信息。 When someone clicks a tab, the map and info slides down and shows up the proper marker (4 separate maps), however I can't get the first one to work so I can't copy/paste it. 当有人点击选项卡时,地图和信息会向下滑动并显示正确的标记(4个单独的地图),但是我无法让第一个工作,所以我无法复制/粘贴它。

Here is my code: 这是我的代码:

Script: 脚本:

var latlng = new google.maps.LatLng(42.3535727, -83.0591444);
var options = {  
      zoom: 14,  
      center: latlng,  
      mapTypeId: google.maps.MapTypeId.ROADMAP,
    };
var map = new google.maps.Map(document.getElementById('detroit_map'), options);
marker1 = new google.maps.Marker({  
            position: new google.maps.LatLng(42.3535727, -83.0591444),
            map: map
          }); 
map.setCenter(latlng);

Html: HTML:

<div id="detroit_map" style="width:270px;height:170px;"></div>

PS, I get no errors in chrome developer tools. PS,我在chrome开发人员工具中没有错误。

It's hopefully something really simple that I overlooked. 希望我忽略了一些非常简单的事情。

Thanks 谢谢

Found the answer for future viewers : 找到了未来观众的答案

Turns out, my tabs causing the display between block, and none were making my map load weird. 事实证明,我的标签导致了块之间的显示,没有一个让我的地图加载怪异。 I made an initialize function for each, and called setTimout('functionName', 1000); 我为每个做了一个初始化函数,并调用了setTimout('functionName',1000); to call the maps to load. 调用地图加载。

I changed my map code a little bit, but everything can we found on w3schools under their tutorial. 我稍微更改了我的地图代码,但是我们可以在教程下的w3schools找到所有内容。

Initialize the map after the tab is clicked. 单击选项卡后初始化地图。 This also works for the iframe google map, when used inside a tab. 当在标签内使用时,这也适用于iframe谷歌地图。

Tell your map to resize.. 告诉你的地图调整大小..

google.maps.event.trigger(map, 'resize');

map is the map instance that is returned by map是返回的地图实例

map = new google.maps.Map(document.getElementById("map_canvas"), {
     mapTypeId: google.maps.MapTypeId.ROADMAP
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM