views:

493

answers:

4

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 fallbacks.
  • Check for a stored Location. If it's stored, use it. If not, go on...
  • Check for the user's chosen time.
A: 

I would also like to know if there is a cache of some sorts. I am playing with core location at the moment myself. I rekon using the device locale to zoom in on the city or timezone area may not be a bad idea to at least have the map in a rough position. You would probably need to give them a facility to search for a POI manually and if they have internet connection zoom in on that?

vladzz
This should be a comment, but considering your rep, I understand the fact that you posted an answer.
Moshe
A: 

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]
Paul Lynch
+1  A: 

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.

unforgiven
A: 

Does anyone know what's the input to Core Location function calls before it outputs the Geo-Location to the users?

U-Fong