2

我有几个关于核心位置的问题。

1)用户是否应该拒绝我的应用程序使用核心位置的权限,或者核心位置由于某种原因不可用,是否有回退?(例如设备区域设置?)

2)我可以缓存设备的位置以备下次使用吗?核心位置自己做吗?

3)我真的需要在春季中期用户区域的日落时间,一旦我有设备的纬度和经度,我就有一个功能可以做到这一点。也许我可以根据语言环境对时间做出一个假设?(例如:在美国,假设大约晚上 7:00。)

编辑:

我真的想计算应用程序用户区域的日落。与地图无关。我正在考虑以下事件序列:

  • 检查核心位置的可用性。如果是,请使用它并将其存储在 NSUserPreferences 中。如果核心位置不可用,请继续使用后备。
  • 检查存储的位置。如果已存储,请使用它。如果没有,请继续...
  • 检查用户选择的时间。
4

2 回答 2

1

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)我建议尝试使用核心位置,如果出现问题,只需要求用户输入他/她的当地时间或位置(城市应该足以满足您的目的)。如果您选择询问用户的位置,那么您可以获得相应的纬度/经度对,但这需要有效的网络连接。

于 2010-04-08T08:25:35.010 回答
0

2) 来自 CLLocationManager 的在线文档:

位置服务尽快返回初始位置,并在可用时返回缓存信息。

您可以检查 CLLocation 时间戳以查看它是否是缓存值。

3) 如果您决定使用区域设置来进行初始 TZ 近似,请记住用户旅行,并且可能不会立即重置他们的区域设置。您可以通过以下方式获取当前 TZ 对象:

[NSTimeZone localTimeZone]
于 2010-04-05T16:38:45.013 回答