Google Maps-不显示但以HTML格式加载 [英] Google Maps - Not displaying but loaded in HTML

查看:95
本文介绍了Google Maps-不显示但以HTML格式加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么.

但是由于某些原因,我的Google Maps脚本已加载到页面中,但未显示.

But for some reason, my google maps script is loaded in the page, but it is not displayed.

我很好奇我做错了.

这是我的html.

<ul class="address">
<LI><STRONG>Titel:</STRONG><br/>Text
<div class="gmap" address="Stationsstraat 23 8780 Oostrozebeke"></div></LI>
</ul>
<ul class="address">
<LI><STRONG>Titel:</STRONG>Text
<div class="gmap" address="Eredekestraat 56 2000 Antwerpen"></div></LI></UL>

这是我的Javascript(带有jQuery):

And here's my Javascript (with jQuery):

     $(document).ready(function(){
        var coll_gmap = $(".gmap");
        if ( coll_gmap.length != 0 )
        {
            //initiate map
            geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(-34.397, 150.644);
            var myOptions = {
                zoom: 8,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }

            //loop all addressen + insert into map
            coll_gmap.each(function(index)
            {
                map = new google.maps.Map(coll_gmap[0], myOptions);
                 if (geocoder) {
                        geocoder.geocode( { 'address': $(this).attr("address")}, function(results, status) {
                            if (status == google.maps.GeocoderStatus.OK) {
                                map.setCenter(results[0].geometry.location);
                                var marker = new google.maps.Marker({
                                    map: map, 
                                    position: results[0].geometry.location
                                });
                            } else {
                                alert("Geocode was not successful for the following reason: " + status);
                            }//end if status
                        }); //end if geocoder.geocode
                    } //end if geocoder   

            }) //end coll_gmap each

            }//end if coll_gmap length
    }); //end onload


    var geocoder, map;

推荐答案

我发现它是什么.

我必须在

<div> =>(becomes)=>
<div style="width:500px;height:150px"></div> 

很容易忘记,我想:(

这篇关于Google Maps-不显示但以HTML格式加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆