Background GPS in iOS. Is this possible? - iphone

I was wondering if it was possible to get the location of the iPhone with an app that isnt running, or at least running in the background. What I want to do is have the iPhone send a push notification when it arrives at a certain coordinate. Is this possible? If so, could someone put me in the right direction?
Thanks,
Ben

Yes, it is possible. Your application can ask to be notified of significant location changes or to simply continue using the GPS while executing in the background. The former—the approach recommended by Apple—uses less power at the cost of accuracy (this blog post indicates that the updates are accurate to roughly 500m), while the latter is as accurate as the device can manage. This is all detailed in the iOS Application Programming Guide and and the Location Awareness Programming Guide.
If you simply want your application to be notified when the device moves into a particular region, you may want to look into CLLocationManager's startMonitoringForRegion:desiredAccuracy:. If the device moves into a particular geographical region, your app is launched (even if it's not running!).

Related

Is it possible to get distance from user location to specific location in background in IOS?

I need to calculate distance from user location to specific location, when the app is in background, and get a local notification based on that.
Background location tracking is totally possible, and I have already done that, but is it possible to execute a block of code, containing some condition checking and based on that update and get a local notification?
I am not getting any proper solution. Is there any way to do so?
Can you help me please?
Yeah, you can definitely do that. I'm doing it in an app right now. Use significant location changes, or regions, as previously suggested, to keep the pressure off the users battery as much as possible.
We observe regions (and significant location changes where regions are not supported by the device) then check a few things and fire off a local notification if needs be.
We started with a basic prototype to prove the concept and I highly recommend that approach as a way to get familiar with the location and notification frameworks.
Start with the Location Awareness Programming Guide. Most everything you need to know is in there. (Most things that aren't in there are simply impossible for an AppStore app.) See also Tracking the User's Location in the iOS App Programming Guide.
The best tool for what you're describing is likely "Shape-Based Regions." You can basically draw a box on a map and say "when the user enters or leaves this box, let me know." If at all possible, this is the tool you should use. It has the least impact on battery life.
If you absolutely cannot solve the problem any other way, it is legal to request background location delivery with startUpdatingLocation (and the appropriate background mode in Info.plist; see the above docs). An app that tracks your route while you hike would be be appropriate for this kind of setup. But you should avoid it if at all possible since it's a major battery drain.
You will want to update for significant locations in the background: http://mobile.tutsplus.com/tutorials/iphone/ios-multitasking-background-location/. Then you will want to create a location notification based on that.
My issue is that I am not sure if you can create a local notification in the background.

How to make iPhone track itself on a map?

For Example, I travel from San Diego to La, I want the iPhone to track how long it was from San Diego to La and tell me the result?
When your app is in the background it could still receive location info when there is a significan location change such as new cell tower. Your app could monitor the significan location changes as well as regular gps when it's available and calculate the time difference.
Check out Starting the Significant-Change Location Service
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html#//apple_ref/doc/uid/TP40009497-CH2-SW10
Also this is a good tutorial for using significan time change notifications:
http://www.mindsizzlers.com/2011/07/ios-background-location/
For basic MapKit usage check out this tutorial.
You can use CoreLocation to track the phone with GPS, storing the position every so often (either do it every X minutes, or every X miles/degrees-latitude-longitude.
The CLLocationManager class is what you want, most likely. You give it a delegate that receives events, and start it polling. To conserve battery, you don't necessarily want it to be polling continuously, but you can set it up to automatically turn off and then back on again in a little while.
Displaying it on a map is slightly more complicated, but still quite easy to do. If you need Geocoding, you'll probably need to use the Google Maps API.

iphone gps accuracy, can it trigger an event based on location?

I have an issue that i am having trouble to solve. We are about to develop an iphone locative application that would take you around the city with audio that would be played based on the location. I was wondering, do you know how accurate the iphone GPS will be? In terms of actual distance. I am reading 250 m on line but it looks a lot. Plus the gps in the iphone finds my location more precisley than 250 m. I know it is a generic question, but mabe you guys can give me a feedback about it, i am quite desperate and exausted. what we would live to do is, every 70-80 m, put a pin on a map with an audio file, when the user crossed the pin it would trigger an event that is the audio file. I just would love to know how accurate the gps could be so that i can start designing the experience.
Thanks a lot
I've seen iPhone's GPS as accurate as 3m (at least that's what it said on my device when testing).
There is also a new API since iOS 4.0 that you might be interested in that will enable you to set a region for the device to monitor and it will automatically generate a callback when the user crosses the virtual fenceline depending on how accurate you need that to be. This is particularly useful when the app is sent to the background since you can simply monitor the user's location using CLLocation when the app is in the foreground:
- (void)startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy
You can get up to 5 meters accuracy. Within the core location framework there is a property - horizontalAccurracy - that you can read at runtime to get the accuracy for a given moment
The accuracy is anywhere from 5-25m.

Periodically 'ping' the iPhone GPS?

I'm trying to create an app similar to TravAlert which apparently 'pings' the GPS periodically to figure out where you are. Unfortunately, I'm having a heck of a time figuring out how to do it.
I can't use an NSTimer to fire off the GPS checks because NSTimer doesn't run in the background (which this app presumably must do). I can't use Local or Push notifications as "timers" because they automatically come with a notification and I don't want the use to know every single time that the GPS was queried.
I also tried using CoreLocation's startMonitoringSignificantLocationChanges and that works to a degree, but I can just see the case where the user happens to be in a region of poor cell service (apparently startMonitoringSignificantLocationChanges uses cell tower triangulation as a means of determining location) and thus the app fails to fire.
Any idea how TravAlert does it?
Thanks!
P.S. I'm not trying to rip off TravAlert by making a better app - this is for a college class and unfortunately neither my professor or anybody else in my class has the faintest idea as to how to replicate TravAlert's GPS "ping".
startMonitoringSignificantLocationChanges is the right choice for your app. You can get finer detailed location whilst your app is running. The other option to run the GPS in the background is intended for navigation apps hooked up in a car due to high power consumption.

iPhone 4 background location service question

I'm looking into the new background location service options in the iPhone 4 SDK. It allows an app to run in the background and receive location updates from the device.
There are two methods offered. One is a battery intensive mode that continuously gets location updates. The second recommended method sends the app location updates when there has been a "significant location change".
Does anyone know what a significant location change might be? Is a 30 foot walk considered significant, or is a 10 block walk considered significant? I imagine it also depends on the accuracy of the location mechanism being used at the time.
I've recently done some field testing of the new background location service to get an idea of what constitutes a significant location update, what kind of accuracy to expect for the location hits and our general experiences using it.
The results are detailed in a fairly lengthy blog post:
iPhone Background GPS: Accurate to 500 meters, not enough for foot traffic
As Steve Jobs mentioned in the OS 4 introduction, the low power mode uses cell tower triangulation and does not activate GPS unit. Since the iPhone phone module needs to keep a connection to the cell network anyway, there should be no impact on battery life.
Since the precision of a location fix with cell tower triangulation is anywhere between a few dozen meters (in dense city locations) and a few miles, I think 30 ft is not a significant location change. I don't know the specifics, though (and as mentioned by the commenters, the Apple dev forums are the right place to talk about those).