我正在Titanium Appcelerator中创建一个iOS应用程序,其中包含一个仪表板窗口和另外两个窗口。其中一个包含一个加载时间约为3秒的mapview,这是一个很长的时间来查看空白屏幕。
在Appcelerator论坛中,this帖子有人发帖询问如何刷新用户的位置,只有当它改变了一定数量时才会实现。我目前的实施如下:
设置距离过滤器,使其仅在主要移动时刷新
Titanium.Geolocation.distanceFilter = 10;
在无关紧要的起始位置(0,0)创建一个mapview并将其添加到窗口
var mapview = Titanium.Map.createView({
mapType: Titanium.Map.STANDARD_TYPE,
region: {latitude: 0, longitude: 0, latitudeDelta:0.05, longitudeDelta:0.05},
animate:false,
regionFit:true,
userLocation:false
});
win.add(mapview);
获取用户位置并将mapview的位置设置为
//Should only go once
Titanium.Geolocation.getCurrentPosition(function(e)
{
if (e.error)
{
alert('Cannot get your current location');
return;
}
var longitude = e.coords.longitude;
var latitude = e.coords.latitude;
var altitude = e.coords.altitude;
var heading = e.coords.heading;
var accuracy = e.coords.accuracy;
var speed = e.coords.speed;
var timestamp = e.coords.timestamp;
var altitudeAccuracy = e.coords.altitudeAccuracy;
var current = {
latitude : latitude,
longitude : longitude,
latitudeDelta : .05,
longitudeDelta : .05
};
mapview.setLocation(current);
mapview.userLocation = true;
});
我只想让地图快速加载。如果需要几秒钟来确定用户的位置,那很好。但让用户看一个空白的屏幕3秒是很糟糕的。有办法解决这个问题吗?
我也设置了:
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
如果它有所作为。
编辑:我注释了我获取用户位置的部分,地图仍然需要相同的加载时间。我认为这个问题与我在创建map.js文件之前打开它的事实有关。
在我的app.js文件中,我调用map.open()。然后在我的map.js文件的顶部,我做:
var win = Ti.UI.currentWindow;
然后我构建地图并添加它。我不知道如何保留我的架构但预加载地图。这可能吗?
答案 0 :(得分:0)
无需使用任何Titanium.Geolocation方法或事件监听器。尝试仅在mapview上使用用户位置,它会反映地图上的用户位置。
首先只需打开MAP窗口。
距离过滤器适用于Titanium.Geolocation的eventlistener。你能分享一下你的代码吗?然后我会建议你一个合适的解决方案。
如果您想使用Titanium.Geolocation方法或事件监听器来更改地图的位置。
Titanium.Geolocation.getCurrentPosstion()将其放入setInterval函数中,该函数在特定时间间隔后调用函数(Titanium.Geolocation)。在打开地图窗口后使用此功能。
<强> Titanium.Geolocation.addEventListener( '位置',功能(强>){ ... }); 使用距离过滤器,它会在特定距离后触发。