Javascript 谷歌地图在刷新页面后显示为灰色
我是主干和节点js的初学者,我已使用以下命令将google maps添加到我的模板中: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:
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();
},