简体   繁体   English

Google地图未加载图像和标记

[英]Google Maps Not Loading Image and Marker

This is my gmaps avscript code, i print maps as many as my data database, these gmaps are inside at collapsed div: 这是我的gmaps avscript代码,我打印的地图与数据数据库一样多,这些gmaps位于折叠的div中:

var maps = {!! $maps !!};
var googlemaps = [];

$.each(maps, function( key, item ) {
    googlemaps[key] = new GMaps({
        div: '#gmaps-' + key,
        lat: item.latitude,
        lng: item.longitude,
        width: '100%',
        height: '100%',
    });

    googlemaps[key].addMarker({
        lat: item.latitude,
        lng: item.longitude,
        width: '100px',
        draggable: false,
        title: 'Marker'
    });

    googlemaps[key].setCenter( item.latitude, item.longitude );
    googlemaps[ key ].setZoom( 15 );
});

The div by default is collapsed, after i open the div and show the gmaps, it's just showing blank grey maps, i try drag my map to search my marker, it only view a little part of the gmaps panel at the top left. 默认情况下,div是折叠的,打开div并显示gmap后,它只是显示空白的灰色地图,我尝试拖动地图以搜索标记,它仅查看gmaps面板左上角的一小部分。

after i resize my browser the marker finaly can drag to center of panel but still grey. 在我调整浏览器的大小之后,标记的final可以拖动到面板的中央,但是仍然是灰色的。

I zoomed out/in and the image loaded, the image only loaded when i zoom in and out. 我缩小/放大并加载了图像,仅在放大和缩小时才加载图像。

I really confused searching so many answer but not solving my problem. 我真的很困惑,寻找这么多答案,却没有解决我的问题。

Please help me.. 请帮我..

When the map div , or it's parent, or it's parent parent (any predecessor) has display:none style, and you create the map, the map view won't initialize properly. 如果地图div或其父级或父级父级(任何前任)具有display:none样式,并且您创建了地图,则地图视图将无法正确初始化。 You have to trigger resize event on map for it to reinitialize the map view. 您必须在地图上触发resize事件,才能重新初始化地图视图。

In GMaps the google.maps.Map object is accessible using .map attribute, so your code will have to look something like this: GMaps ,可以使用.map属性访问google.maps.Map对象,因此您的代码必须如下所示:

google.maps.event.trigger(googlemaps[key].map, "resize");

Remember to trigger it AFTER the div is visible. 切记在显示div之后触发它。 To be sure you can put the resize trigger into a timeout, when they click the div to display. 为了确保您可以在他们单击div来显示时将大小调整触发器设置为超时。

Side note: I am not sure if you are aware, but every map you create is a separate API call so to have multiple maps results in lot of separate API calls and if you don't have maps for business license you can hit limits pretty fast. 旁注:我不确定您是否知道,但是您创建的每个地图都是一个单独的API调用,因此要拥有多个地图会导致很多单独的API调用,如果您没有营业执照的地图,则可以达到限制快速。

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

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