【问题标题】:Backbone - Geolocation骨干网 - 地理位置
【发布时间】:2013-03-20 23:47:44
【问题描述】:

我是 Backbone 的新用户,并开始在其中实施 Google 地图。我在 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;
}

});

【问题讨论】:

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

标签: backbone.js geolocation maps


【解决方案1】:

不确定我的问题是否正确,但对我来说,每次触发地图路线后拨打google.maps.event.trigger(map,'resize'); 都有帮助。

PS:有点晚了,但也许对以后的人有帮助

【讨论】:

    猜你喜欢
    • 2013-02-15
    • 2013-02-10
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-02
    相关资源
    最近更新 更多