开发者

Core Location - fallback, location caching and alternatives

开发者 https://www.devze.com 2022-12-26 00:21 出处:网络
I have a few questions about Core Location. 1) Should the user refuse permission for my app to use core location, or core location is unavailable for some reason, is there a fallback? (Device Locale,

I have a few questions about Core Location.

1) Should the user refuse permission for my app to use core location, or core location is unavailable for some reason, is there a fallback? (Device Locale, for example?)

2)Can I cache a device's location for next time? Does Core Location do this itself?

3)I really need the sunset time in the user's area during the mid-spring season and I have a function to do that, once I have the Latitude and Longitude of the device. Perhaps I can just make an assumption about the time based on Locale? (Example: In the US, assume approximately 7:00pm.)

EDIT:

I really am trying to calculate sunset in the users area for an app. Nothing to do with the map. I am considering the following sequence of events:

  • Check for Core Location availability. If yes, use it and store it in NSUserPreferences. If Core Location is unavailable, go on to the fallback开发者_运维技巧s.
  • Check for a stored Location. If it's stored, use it. If not, go on...
  • Check for the user's chosen time.


1) Strictly speaking, if the user does not allow using CoreLocation or, if permission were given but CoreLocation is not available, there is no other fallback to get the user's location as a latitude, longitude pair. Using the locale may not work in all of the cases. First, it will just give you an approximation which may be way too far from reality. However, it's up to you to judge whether this approximation is ok for your app. Moreover, there are some users using a locale different from the one related to their country. And, you have no guarantee that people travelling abroad will adjust the date/time every time.

2) Core Location caches by default the last location retrieved from the GPS unit. However, for people travelling abroad this cached location will be certainly wrong (even for people travelling just a few miles away), and in general, you should discard the cached value and localize again the user each time. I understand that for people travelling within their country this will not (usually) create huge problems. But it just depends on the country: travelling within Italy will not change the time, but travelling across the US may change the time up to 3 hours.

3) I would suggest to try using Core Location and, in case of problems, simply ask the user to input his/her local time or location (the city should be enough for your purpose). If you choose to ask for the user's location, then you can get the corresponding latitude/longitude pair but this will require a working network connection.


2) From the online docs for CLLocationManager:

The location service returns an initial location as quickly as possible, returning cached information when available.

You can check the CLLocation timestamp to see if it is a cached value or not.

3) If you do decide to use locale for an initial TZ approximation, remember that users travel, and may not reset their locale promptly. You can get the current TZ object with:

[NSTimeZone localTimeZone]
0

精彩评论

暂无评论...
验证码 换一张
取 消