2013-03-20 2 views
0

새로운 백본 사용자를 찾고 있으며 Google지도를 구현했습니다. 나는 이것을 View 객체에서 설정했다. 괜찮 았어.하지만 다른 페이지 (네비게이터 개체가있는 템플릿)로 가서 Google지도가있는 페이지로 돌아 가면 Google지도에서 현재 위치가 표시되지 않습니다. 내보기에서 내 코드 아래백본 - 위치 정보

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; 
} 

});

+0

에서 누군가가 초기화 기능을 사용하면 페이지를 방문 firsttime 호출되는가요 데 도움이 두 번째로 당신은 페이지를 방문? this.render()는 this.model.bind ('reset', this.render)와 같이 모델에 바인딩되어야합니다. – powerfade917

답변

0

질문이 맞는지는 모르겠지만지도 루트를 실행 한 후 매번 google.maps.event.trigger(map,'resize'); 번으로 전화하면 도움이되었습니다.

추신 : 조금 늦게,하지만 어쩌면 그것은 미래