javascript - 不要使用 Gmaps.js 显示 Google map

标签 javascript google-maps gmaps.js

我想在我的网页中使用 Google map 。我用过Gmaps.js为了它。我的代码如下:

  <div class="row col-md-10 col-md-offset-1">
    <br>
    <br>
    <br>
    <label for="address">{{$MapLabel}}</label>

    <div class="span11">
        <div id="map"></div>
    </div>
    <br>
    <br>
    <div class="row">
        <div class="col-md-4">
            <button id="button_Google_Serach" type="button" class="btn btn-info" >جستجو</button>
        </div>
        <div class="col-md-8">
            <input  type="text" id="address_with_google" name="address_with_google" placeholder="{{$SearchLabel}}" class="form-control" />
        </div>
    </div>
    <input type="text" hidden id="latGoogleMap">
    <input type="text" hidden id="lngGoogleMap">
    <br>
</div>

当我编写下面的代码时,我没有看到任何谷歌地图 div 相同的下面的图像。

var map;
$(document).ready(function(){

  map = new GMaps({
    el: '#map',
    lat: -12.043333,
    lng: -77.028333,
    zoom: 16,
    click: function(e){

      map.removeMarkers();

      map.addMarker({
        lat: e.latLng.lat(),
        lng: e.latLng.lng(),
        draggable: true
      });

      //Set google lat in hidden input
      $('#latGoogleMap').val( e.latLng.lat());
      //Set google lng in hidden input
      $('#lngGoogleMap').val(e.latLng.lng());

    }

  });

});

enter image description here

但是当我删除该代码时,我看到了: enter image description here

我该怎么办?

最佳答案

使用谷歌地图的高度和宽度:

 map = new GMaps({
        el: '#map',
        lat: -12.043333,
        lng: -77.028333,
        width: '95%',
        height: '350px',
        zoom: 16,
        click: function(e){

          map.removeMarkers();

          map.addMarker({
            lat: e.latLng.lat(),
            lng: e.latLng.lng(),
            draggable: true
          });

          //Set google lat in hidden input
          $('#latGoogleMap').val( e.latLng.lat());
          //Set google lng in hidden input
          $('#lngGoogleMap').val(e.latLng.lng());

        }

      });

关于javascript - 不要使用 Gmaps.js 显示 Google map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41550870/

相关文章:

带有 gmaps.js 的 Jquery 对话框

javascript - ExtJS View 创建

javascript - 给定值创建菱形的函数

javascript - 按自定义 Angular 数据表中的列进行过滤

javascript - 如何从 map 外部触发 Google map 标记

iphone - 强制 MapKit 仅使用缓存的 map 图 block /以编程方式禁用网络

javascript - Gmaps.js 从数组中添加/删除标记

javascript - 循环内的传单bindpopup

javascript - 为列表 Google map 中的每个纬度、经度创建一个标记

javascript - gmaps.js |添加新标记时删除旧标记