Backbone.js 主干网-地理定位

Backbone.js 主干网-地理定位,backbone.js,geolocation,maps,Backbone.js,Geolocation,Maps,我是一个新的骨干用户,并开始在其中实现谷歌地图。我在de View对象中设置了这个。我工作得很好,但是当我转到另一个页面(带有导航器对象的模板)并返回带有谷歌地图的页面时,当前位置在谷歌地图上不起作用 下面是我的代码 DFM.MapView = Backbone.View.extend({ el: $("#content"), template: $("#rankings_template").html(), // Initialiseren initialize: function(){

我是一个新的骨干用户,并开始在其中实现谷歌地图。我在de View对象中设置了这个。我工作得很好,但是当我转到另一个页面(带有导航器对象的模板)并返回带有谷歌地图的页面时,当前位置在谷歌地图上不起作用

下面是我的代码

DFM.MapView = Backbone.View.extend({

el: $("#content"),

template: $("#rankings_template").html(),

// Initialiseren
initialize: function(){

    self = this;
    this.render();

    var location_destiny = new google.maps.LatLng(52.476716,4.799623);

    var map = new google.maps.Map(document.getElementById('google_maps'), {
        center: location_destiny,
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        panControl: false,
        zoomControl: false,
        mapTypeControl: false,
        scaleControl: false,
        streetViewControl: false,
        overviewMapControl: false

    });

    if(navigator.geolocation){

        navigator.geolocation.watchPosition(update_user_location, error_handler, {
            enableHighAccuracy: true,
            frequency: 3000
        });

    } else {
        console.error('Geolocation: 0 - Geotracking not available'); 
    }

    // Update user location
    function update_user_location(position){
        location_user = new google.maps.LatLng(52.474716,4.798623);

        var marker_user = new google.maps.Marker({
             title: 'Gebruiker',
             position: location_user,
             map: map,
             draggable: true,
        });
    }

    // Error handler
    function error_handler(error){
        console.error('Geolocation: ' + error.code + ' - ' + error.message);
    }

    var marker_destiny = new google.maps.Marker({
         title: 'Bestemming',
         position: location_destiny,
         map: map,
         draggable: true,
    });
},

render: function(){

    this.$el.html(_.template(this.template));

    return this;
}

}))

不确定我的问题是否正确,但对我来说,它有助于调用
google.maps.event.trigger(map,'resize')每次触发地图路线后


PS:有点晚了,但可能对将来的人有帮助

第一次访问页面和第二次访问页面时是否会调用初始化函数?this.render()需要与您的模型绑定,如this.model.bind('reset',this.render');