In Windows Phone app I get the geoposition like this:
Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10));
If I understand this correctly maximumAge means that the location can be cached and max 5 minutes old.
Can I use this "build in caching" so that when my app starts, I use GetGeopositionAsync(...) with maximumAge eg 2 (min), just to get fresh geopostitin with out actually using the geoposition.
Later in the app when I actually need the location, I call again GetGeopositionAsync(...) with maximumAge eg 10 (min). Now I should get the cached value (if it is still valid based on maximumAge)?
Does this make any sense? If this works as I expected, I do not need to build my own geoposition caching system.
Yes, that is correct. An MSDN blog post ( http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/11/30/acquiring-a-single-geoposition-in-windows-phone-8.aspx ) explains the caching using MaximumAge
pretty good:
MaximumAge
defines a limit of how old a cachedGeoposition
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 theGeolocator
handle the caching.For example, if the app sets
MaximumAge
to 5 minutes, the Geolocator can satisfy that request with aGeoposition
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:
The request is started.
Identify whether a cached
Geoposition
satisfies the age and desired accuracy, and if so, immediately return it.Trigger positioning technologies based on the desired accuracy.
Return a
Geoposition
when 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, 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.