0
我是一位新的骨干用户,并开始在其中实施Google地图。我在View对象中设置了它。我工作得很好,但是当我转到另一个页面(带有导航器对象的模板)并返回到Google Maps的页面时,当前位置不会在Google Map上销售。主干 - 地理位置
下面我的代码从我的浏览
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;
}
});
是初始化函数被调用firsttime您访问的页面和第二次您访问的页面? this.render()需要像这样与你的模型绑定this.model.bind('reset',this.render); – powerfade917 2013-03-23 18:44:58