Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图在刷新页面后显示为灰色_Javascript_Google Maps_Backbone.js_Gruntjs_Marionette - Fatal编程技术网

Javascript 谷歌地图在刷新页面后显示为灰色

Javascript 谷歌地图在刷新页面后显示为灰色,javascript,google-maps,backbone.js,gruntjs,marionette,Javascript,Google Maps,Backbone.js,Gruntjs,Marionette,我是主干和节点js的初学者,我已使用以下命令将google maps添加到我的模板中: script(src='/lib/google-maps/lib/Google.js') script(src='http://maps.googleapis.com/maps/api/js') script(src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js') div.googleMap( style='width:

我是主干和节点js的初学者,我已使用以下命令将google maps添加到我的模板中:

script(src='/lib/google-maps/lib/Google.js')
script(src='http://maps.googleapis.com/maps/api/js')
script(src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js')
div.googleMap( style='width: 250px; height: 250px;')
在我看来:

mod.mapTemplate = Marionette.ItemView.extend({
template: '#actors-map-template',
initialize: function () {
  var mapProp = this.model.get('mapProp');
  map = new google.maps.Map(this.$el[0], this.model.get('mapProp'));
  }
});
我添加了许多功能,如:

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

但是,同样的事情是徒劳的:谷歌地图第二次出现,但是是灰色的。 问题是map的变量rmiURL第二次未定义,而第一次它包含此URLttps://www.google.com/maps/@38.9891271,1.2130107,6z/数据=!10毫升!1e1!12b1?源=apiv3和rapsrc=apiv3
对于HTML:在我的div之后,它生成了另一个类为“gm style”的div,第二次他没有

对于那些有相同问题的人,我找到了解决方案:

initMap: function () {
  this.$el.addClass('temp');
  $('body')
    .append(this.$el);
  var mapProp = this.model.get('mapProp');
  this.map = new google.maps.Map(this.$el.find('.map-canvas')[0],
    mapProp);
  this.$el.remove();
  this.$el.removeClass('temp');
},
render: function () {
  this.$el.html(_.template($('#actors-map-template')
    .html()));
  this.initMap();
},
并且认为:

.map画布(style='width:250px;height:250px;') .temp(style='position:absolute;visibility:hidden;')

initMap: function () {
  this.$el.addClass('temp');
  $('body')
    .append(this.$el);
  var mapProp = this.model.get('mapProp');
  this.map = new google.maps.Map(this.$el.find('.map-canvas')[0],
    mapProp);
  this.$el.remove();
  this.$el.removeClass('temp');
},
render: function () {
  this.$el.html(_.template($('#actors-map-template')
    .html()));
  this.initMap();
},