c# - Windows Phone 8 Geolocator 缓存位置

标签 c# caching windows-phone-8 geolocation

在 Windows Phone 应用程序中,我得到这样的地理位置:

Geoposition geoposition = await geolocator.GetGeopositionAsync(
            maximumAge: TimeSpan.FromMinutes(5),
            timeout: TimeSpan.FromSeconds(10));

如果我理解正确的话,maximumAge 意味着位置可以被缓存并且最多 5 分钟。

我可以使用这个“内置缓存”以便在我的应用程序启动时使用 GetGeopositionAsync(...) 和 maximumAge 例如2(分钟),只是为了在不实际使用地理位置的情况下获得新鲜的地理信息。

稍后在应用程序中,当我真正需要位置时,我再次调用 GetGeopositionAsync(...) 和 maximumAge 例如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 进行缓存:

MaximumAge defines a limit of how old a cached Geoposition can 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 the Geolocator handle the caching.

For example, if the app sets MaximumAge to 5 minutes, the Geolocator can satisfy that request with a Geoposition that 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 Geolocator will always take the following sequential steps to satisfy a request:

  1. The request is started.

  2. Identify whether a cached Geoposition satisfies the age and desired accuracy, and if so, immediately return it.

  3. Trigger positioning technologies based on the desired accuracy.

  4. Return a Geoposition when it meets the desired accuracy.

  5. 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, this Geoposition with 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.

关于c# - Windows Phone 8 Geolocator 缓存位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23973895/

相关文章:

java - 如何使用泛型初始化 ehCache 列表?

c# - HTML Agility - 寻找正确的节点

c# - 在 C# 中将字符串格式化为电话号码

c# - 自定义无符号整数限制和翻转

python - Django Memcached 缓存消失

php - 如何缓存 php soapclient 响应?

checkbox - 我可以更改 LongListMultiSelector 中的 CheckBox 颜色吗? WP8

c# - 如何实现双指缩放

c# - Marshal.AllocHGlobal VS Marshal.AllocCoTaskMem,Marshal.SizeOf VS sizeof()

c# - 在属性中指定 T