【问题标题】:jQuery gmap is not showing on websitejQuery gmap 未在网站上显示
【发布时间】:2014-09-30 22:04:15
【问题描述】:

我下载了一个已经集成了 gmap 的模板。我所要做的就是调整标记,使其指向正确的位置。

我正在创建一个新网站,在联系页面上,我想添加与模板上相同的 gmap。

我使用相同的代码,复制相同的文件并将它们放在各自的目录中,但我无法让地图显示在我的页面上。

在 HTML 文档的 HEAD 中,我包含了以下代码:

 <script src="https://maps.googleapis.com/maps/api/js"></script>

在 BODY 的更下方,我创建了一个像这样的 SECTION 标签:

 <section id="map-section">
      <div id="map"></div>
 </section>

就在结束的 BODY 标记上方,我有这些 Javascript:

<script src="js/jquery-1.11.0.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/jquery.gmap.js"></script>
<script type="text/javascript">
  jQuery(document).ready(function() {
    jQuery('#map').gMap(
      {
        latitude: 50.000000,
        longitude: 50.000000,
        html: "My Location",
        popup: true,
        panControl: true,
        zoomControl: true,
        zoomControlOptions:
        {
          style: google.maps.ZoomControlStyle.SMALL
        },
        mapTypeControl: true,
        scaleControl: true,
        streetViewControl: false,
        overviewMapControl: true,
        scrollwheel: true,
        icon:
        {
          image: "http://www.google.com/mapfiles/marker.png",
          shadow: "http://www.google.com/mapfiles/shadow50.png",
          iconsize: [20, 34],
          shadowsize: [37, 34],
          iconanchor: [9, 34],
          shadowanchor: [19, 34]
        },
        zoom:15,
        markers: [{
          latitude: 50.000000,
          longitude: 50.000000
        }]
      });
    });
 </script>

另外,在我的 CSS 中,我的 MAP-SECTION 看起来像这样:

#map-section {
  bottom: 0px;
  padding: 0px;
  height: 250px;
  width: 100%;
  z-index: 0;
  border: 1px solid red;
}
#map{
  display: block;
  height: 250px;
  width: 100%;
  min-width: 100%;
  max-width:1350px;
  margin-left:auto;
  margin-right:auto;
}

如果您在 CSS 中注意到,在 #map-section 中,我在屏幕上添加了一个红色边框。它只是没有显示地图。

谁能看到我错过了什么?

请帮忙。

【问题讨论】:

  • 在浏览器中调试会出现javascript错误吗?

标签: javascript jquery html map jquery-gmap3


【解决方案1】:

在脚本标签中包含这里提到的所有 js 文件。 maps.google.com/maps/api/js?sensor=false, jquery.ui.map.js, jquery.ui.map.extensions.js, jquery.ui.map.overlays.js, jquery.ui.map.services.js

<div id="map_canvas" style="width:100%; height:500px;"></div>

var mapa = $('#map_canvas').gmap({'center': '-18.646245,35.815918'});
        $('#map_canvas').gmap('option', 'zoom', 7);

        //create the layer (all countries except Mozambique)
        var world_geometry;
        $('#map_canvas').gmap().bind('init', function(event, map) {
            world_geometry = new google.maps.FusionTablesLayer({
                query: {
                    select: 'geometry',
                    from: '1N2LBk4JHwWpOY4d9fobIn27lfnZ5MDy-NoqqRpk',
                    where: "ISO_2DIGIT NOT EQUAL TO 'MZ'"
                },
                styles: [{
                        polygonOptions: {
                            fillColor: "#333333",
                            fillOpacity: 0.3
                        }
                    }],
                map: map,
                suppressInfoWindows: true
            });

        });

            $('#map_canvas').gmap().bind('init', function(event, map) {
                $(map).click(function(event) {
                    $('#map_canvas').gmap('clear', 'markers');
                    $('#map_canvas').gmap('addMarker', {
                        'position': event.latLng,
                        'draggable': true,
                        'bounds': false
                    }, function(map, marker) {
                    }).dragend(function(event) {
                        google.maps.geometry.poly.containsLocation(event.latLng,                       world_geometry);
                    }).click(function() {
                    })
                });
            });

对于现场演示,请查看此 jsfidlle "http://jsfiddle.net/Lq2p5/"

【讨论】:

  • 我添加/包含了您上面引用的所有文件,并且我使用了您上面使用的相同 DIV,但我的页面上没有显示任何内容。有什么想法吗?
  • 在小提琴上检查过吗?我认为这是浏览器的问题。检查浏览器的控制台是否有错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-25
  • 1970-01-01
  • 2019-03-10
  • 1970-01-01
  • 2015-12-16
  • 1970-01-01
  • 2015-12-13
相关资源
最近更新 更多