iPhone Development: CoreLocation and MapKit - iphone

How bad is it to use Location Manager to retrieve the location information when MapView.showUserLocation is also TRUE?
I have a situation where i want to show the blue dot to indicate the user's current location, and i want to record the user's current location after some time interval. Having said that, there may be situations where the user's current location is now being shown, but i still want to get the user's current location.
I think i'll have to use the Location Manager in my controller class, but setting showUserLocation = YES would mean that i'll be draining more battery since two Location Managers are working at the same time? Is this assumption correct?

As discussed on other communities, you can have mapView.showUserLocation = YES and still use CLLocationManager to retrieve the most current location information.
In general there's no conflict involved with having multiple CLLocationManager instances running at the same time.

Just save the coordinates in an array and draw mapannotations for past recorded locations. You dont need to run multiple location managers.

Related

iPhone Location Services is turned off, but the application can still get the location?

I turned off the Location Services on my iPhone, because I don't want the app to determine my location. But, when I run the app it somehow gets my location! Any ideas?
As the docs suggests here
Locations
An array of CLLocation objects containing the location data. This array always contains at least one object representing the current location. If update events were deferred or if multiple events arrived before they could be delivered, the array may contain additional entries. The objects in the array are organized in the order in which they occurred. Therefore, the most recent location update is at the end of the array.
So the location manager always shows some value.

Changing a UITableViewController dynamically via location

I am in the process of building an app, for the record I am using the code from the ECSlidingView controller. I would like for my app to use the GPS to pull data from my web interface letting the user know that they can do certain things at a given location. So for example, I have a user go to a store and lets say I want them to make a payment at that location, it will given them that option. Or if the store doesn't offer payment through the app, I disable that. What would be a good way to go about this?
You could try using CoreLocation but you might have trouble getting accurate location inside (it will most probably use wifi or cellular info so the accuracy might not be what you expect). Then, when you get the location, issue a request to your service passing latitude and longiude you receive from CoreLocation. There, you should search by location to retrieve possible matches - consider returning muliple store infos for nearby stores due to the accuracy issues.

Monitoring Shape based region vs. Starting the Significant-Change Location Service

I am currently working on a location-based reminder app and I am trying to understand iOS 4/5 location services and some of the core location features. Since I want to use geo-fences of different sizes (user can choose the size), I was wondering if I need to combine Significant-Change Location Service with region monitoring or if it is enough to simply use Region Monitoring by itself to make those reminders go off.
As far as I understand Significant-change Location Service, my app would only get a location update if I switch cell towers. Would that mean that in case the geo-fence was somewhere in between that the reminder would not go off?
Compared to that how does Region Monitoring work, other than of course monitoring regions? Will the reminder always go off or are there any blind spots? If so, does DistanceFilter play a role here?
Thanks for the help.
Your use case should be covered with region monitoring.
As far as I understand Significant-change Location Service, my app would only get a location update if I switch cell towers. Would that mean that in case the geo-fence was somewhere in between that the reminder would not go off?
This might happen and is an edge case that you would have to cover. I really depends on many things, location accuracy being one of them. You would definitely have to test that one thoroughly.
Compared to that how does Region Monitoring work, other than of course monitoring regions? Will the reminder always go off or are there any blind spots? If so, does DistanceFilter play a role here?
Last time I checked (> 10 months) region monitoring wasn't always accurate enough. It worked but used cell towers more than the current position to monitor for regions. What that means: Don't rely on region changes alone and dont' expect them to be accurate to the meter.

How does apps like foursquare or gowalla implement their check-in feature?

If I had to build my own check-in feature from scratch, how would I go about it? I was thinking that once a location is determined using corelocations, I can add that location co-ordinate and timestamp to a database in some server. Now once one of my friends check-in close to that location, there can be a query to the database to figure out all check-ins around that location and around that timestamp. Is that how they implement this feature?
Those services use the current location (that you could get via CoreLocation or otherwise) in order to determine which venues to show near the user. Note that they usually have a database of business venues and the user selects the one they are actually and perform the checkin.
So, in order to figure out "who you are hanging out with", they only have to see who has checked in in that specific location, around that timestamp.
Note that the whole thing could have been implemented without location services and geographical coordinates - just choose from a list! Now, with location services, you can help the user search for the place quickly.

Core Location - fallback, location caching and alternatives

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.
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]