繁体   English   中英

Titanium Appcelerator Mapview需要很长时间才能打开

[英]Titanium Appcelerator Mapview Takes a Long Time to Open

我正在Titanium Appcelerator中创建一个iOS应用程序,其中包含一个仪表板窗口和2个其他窗口。 其中之一包含一个地图视图,该视图需要约3秒钟的时间加载,这对于查看空白屏幕来说是很长的时间。

在Appcelerator论坛中,有人发布了帖子,询问如何刷新到用户的位置,仅当它改变了一定程度时才实现(我已实现)。 我当前的实现如下:

  1. 设置距离过滤器,使其仅在主要移动时刷新

     Titanium.Geolocation.distanceFilter = 10; 
  2. 在无关紧要的起始位置(0,0)创建地图视图,并将其添加到窗口中

     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); 
  3. 获取用户位置并为其设置地图视图的位置

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

然后我构建地图并添加它。 我不知道保留我的体系结构但预加载地图的方法。 这可能吗?

无需使用任何Titanium.Geolocation方法或事件监听器。 尝试仅在mapview上将用户位置设置为true,它会反映用户在地图上的位置。

首先,只需打开MAP窗口。

距离滤镜可以与Titanium.Geolocation事件监听器配合使用。 您能否分享您的代码? 然后,我建议您采取适当的解决方案。

如果要使用Titanium.Geolocation方法或事件监听器来更改地图的位置。

Titanium.Geolocation.getCurrentPosstion()将其放入setInterval函数中,该函数在特定时间间隔后调用function(Titanium.Geolocation)。在打开地图窗口后使用此功能。

Titanium.Geolocation.addEventListener('location',function( ){...}); 使用距离过滤器,它会在经过特定距离后触发。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM