有人可以帮帮我吗?我有一个sencha地图,可以跟踪我当前的位置,并绘制线条。但我也想要一个按钮来停止跟踪。所以我想设置autoUpdate: false;
但我真的不知道该怎么做......
这是我的代码
Ext.application({
name: 'Applicatie3.',
launch: function() {
var view = Ext.create('Ext.NavigationView', {
fullscreen: true,
items: [{
title: "I'm lost",
xtype: 'tabpanel',
items:[{
title : 'Home',
xtype : 'map',
iconCls : 'home',
mapOptions : { zoom: 20 },
useCurrentLocation : true,
listeners : {
maprender: function(comp, map){
var marker = new google.maps.Marker({
position : new google.maps.LatLng( ),
map : map
}),
infowindow = new google.maps.InfoWindow({
content : '........'
}),
route = [ ],
geo = Ext.create('Ext.util.Geolocation', {
frequency : 3000,
autoUpdate : true,
allowHighAccuracy : true,
listeners : {
locationupdate : function(geo) {
polyline = new google.maps.Polyline({
path : route,
strokeColor: "red",
strokeOpacity: 1.0,
strokeWeight: 5
});
polyline.setMap(map),
//alert(route);
route.push( new google.maps.LatLng( geo.getLatitude(),geo.getLongitude() ) );
marker.setPosition(new google.maps.LatLng( geo.getLatitude(),geo.getLongitude() ) );
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
},
locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
if(bTimeout){
alert('Timeout occurred.');
} else {
alert('Error occurred.');
}
}
}
});
geo.updateLocation();
}
}
} ]
}]
});
}
});
答案 0 :(得分:1)
我用一个设置为false的全局变量解决了这个问题,当我按下开始按钮时,变量变为true。在函数中我有一个if(true){do location update},当变量设置为false时,位置更新不起作用。
答案 1 :(得分:0)
寻找setAutoUpdate()方法? - http://docs.sencha.com/touch/2-1/#!/api/Ext.util.Geolocation-method-setAutoUpdate
答案 2 :(得分:0)
您需要某种类型的侦听器来发起事件。
使用Toolbar添加Button(请注意'处理程序'配置)或为google.maps.Map中的事件添加侦听器(请参阅{{3获取该对象并getMap(0添加侦听器。)
但是你决定这样做,在处理函数中为地图做this并调用Ext.ComponentQuery('map')。
希望这有帮助。