在Windows Phone应用中,我得到这样的地域:
<code>Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10));
</code>
如果我正确理解此信息,则maximumAge表示该位置可以缓存,并且最长可以使用5分钟.
我可以使用此“内置缓存”功能,以便在我的应用启动时,将GetGeopositionAsync(…)与maximumAge一起使用,例如2分钟(分钟),实际上是在不使用地理区域的情况下获得新鲜的geopostitin.
稍后在应用中,当我真正需要该位置时,我会再次调用具有maximumAge的GetGeopositionAsync(…),例如10(分钟).现在,我应该获取缓存的值(如果基于maximumAge仍然有效)?
这有道理吗?如果这能按我预期的那样工作,则不需要构建自己的地理缓存系统.
解决方法:
对,那是正确的.一个MSDN博客文章(http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/11/30/acquiring-a-single-geoposition-in-windows-phone-8.aspx)很好地解释了如何使用MaximumAge进行缓存:
MaximumAgedefines a limit of how old a cachedGeopositioncan be,
from the time the operation starts, for it to be used by the app. By
default, the request will not return a cached Geoposition. If your app
can use cached positions for a brief period of time, this parameter
also can be seen as the validity time span. The app can simplify its
logic by letting theGeolocatorhandle the caching.For example, if the app sets
MaximumAgeto 5 minutes, the Geolocator
can satisfy that request with aGeopositionthat is as old as 5
minutes from the time the request is started, as long as that position
meets the accuracy requirement specified by the app.Note that the
Geolocatorwill always take the following sequential
steps to satisfy a request:
The request is started.
Identify whether a cached
Geopositionsatisfies the age and desired accuracy, and if so, immediately return it.Trigger positioning technologies based on the desired accuracy.
Return a
Geopositionwhen it meets the desired accuracy.When the timeout is reached, if no position is available yet, error out. If there is a position available, given that the framework
follows a best-effort model, thisGeopositionwith a lower accuracy
than desired by the app can be returned at this time. The app can
decide whether the information is useful or to discard it.
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!