I'm trying to retrieve data from GPS, but it's not so accurate. Here is a screenshot :
It worked great with GPS emulation on the simulator. I want to know how to improve this.
Here is the code I tried :
UserLocation = [[CLLocationManager alloc] init];
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000
[UserLocation setPausesLocationUpdatesAutomatically:NO];
[UserLocation setActivityType:CLActivityTypeFitness];
#endif
UserLocation.delegate = self;
[UserLocation setDistanceFilter:kCLDistanceFilterNone];
[UserLocation setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
[UserLocation startUpdatingLocation];
and then I retrieve data every second and check if it's different than the previous one.
Ric Perrott is right about the GPS data never being 100% accurate all the time. I suggest you set your accuracy to kCLLocationAccuracyBest which according to Apple is the right setting for what you are trying to do.
To try and filter out some of the 'jumping' you are getting, I suggest taking an average reading. For example, take X number of GPS readings (5 or 10 or...) and then average out. This will eliminate the occasional incorrect reading your device might get.
I wrote a fitness walking app a while back and had similar issues. Averaging did not completely resolve the issue but it did smooth it out a lot.
Related
I have an app that tracks user location using the following:
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
According to Apple's documentation, Core Location will try to obtain the best possible reading until I tell it to stop. However, I realize the reading can be impaired by many uncontrollable things i.e. weather, device in a building, etc.
For the purposes of my app, I would like to store how accurate the reading actually was. For example, if I am in a field, I may get a reading that is accurate up to 10 meters, but if I were in that same field during a thunderstorm, I may get a reading that is accurate up to 100 meters.
Is there a way to detect how accurate my reading actually is?
CLLocation (the object that gets returned from the CLLocationManager) contains two properties, horizontalAccuracy and verticalAccuracy.
This is a value measured in metres that tells you how many metres radius around the given location you could be.
You can read more about CLLocation here... CLLocation Class Reference
I believe this is what Apple uses in its maps app to place the circle around the location to represent the area you could possibly be in.
I've encountered problem with startMonitoringForRegion method in iOS 5. Documentation says that method is taking parameter "accuracy":
- (void)startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy
I'm currently developing an app that should notify user when he's in 25 meters radius from monitored point. App uses GPS with kCLLocationAccuracyBestForNavigation setting. I'm creating (CLRegion *)region like this:
CLRegion *pointRegion = [[CLRegion alloc] initCircularRegionWithCenter:pointLocation radius:25.0 identifier:identifier];
and setting accuracy parameter in startMonitoringForRegion for kCLLocationAccuracyBestForNavigation.
Region monitoring works well in my app, however didEnterRegion method fires when user is around 100 meters from monitored region, not 25 meters.
Is there minimum value of radius in startMonitoringForRegion that is not described in Apple's documentation or am I doing something wrong? Is it possible to set region monitoring to relatively small values (like 5-25 meters)?
You cannot set iOS Region Monitoring to lower values unless turning on significantLocationChanges. It's only working in US in bigger cities because region monitoring is based on cellular network.
I'm writing an app that monitors the user's location. I have a CLLocationManager object that uses startMonitoringSignificantLocationChanges, so I can get locations updates from the background when the app is not running. I have setup my application didFinishLaunchingWithOptions so if I get a location key I fire up my manager to get the user's location. Everything works fine but the problem is that every time I get a location from the background, the Horizontal Accuracy of this location is very bad. In most of the cases it is 1414 m.
Does anybody know why the horizontal accuracy is so bad when the location comes from the background?
Is there anything I can do to get locations with better accuracy in the background?
When the app is running all the locations I get are very accurate, this only happens when the location comes from the background. Does that have anything to do with the number of cell towers I have in my city? I was thinking maybe the device doesn't use gps of wifi nodes to get locations in the background.
Anyways, Any help here is appreciated.
Please share your thoughts.
Thanks!
The accuracy of locations returned by CLLocationManager is determined by the desiredAccuracy, which is by default, kCLLocationAccuracyBest, and by the available accuracy of the device. For instance, you may get less accurate locations if the device's battery is low, or you may get more accurate locations if they are still cached from another app.
However, getting you incredibly accurate coordinates drains a significant amount of power from the battery and will drain the device. Applications in the background are probably limited to a much lower resolution of accuracy to improve battery performance.
Accurate locations require a lot of power to use the GPS radio while less accurate locations can rely on nearby wifi hotspots and the cell towers within range of the phone.
As your application resumes from the background, the system will try to improve the accuracy of the results you get. It's a tricky concept, but take a look at the Maps application on your phone. At first, the circle representing your location is very large; as the system gets a more accurate sense of your location, the circle becomes smaller. This visualization represents the phone using more power to get a more precise location.
You'll see a similar phenomenon with CLLocationManager as your app resumes from the background: you'll get an inaccurate location and receive subsequent, more accurate updates.
It's a compromise between convenience and battery life that Apple had to make when designing their APIs. The first update to a user's location probably won't be that accurate unless they were just using the Maps application and the location is cached.
The best advice I can give you is to listen for subsequent updates from the location manager and update your UI accordingly. Good luck!
As the name states: The startMonitoringSignificantLocationChanges notification is only there to let you know that a the the user's location significantly different from the last one checked. It's your job when you receive that Notification to update your location according to the desired accuracy you want.The notification won't do that for you. It is only going to let you know the location has change so you can deal with the situation accordingly. If you don't know how to get a better accuracy you may want to check out the Apple sample code for LocateMe.Here's a snippet that stores the accuracy(bestEffortAtLocation) then tests the accuracy each time the delegate is called until a better result comes in or a time-out occurs.:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// store all of the measurements, just so we can see what kind of data we might receive
[locationMeasurements addObject:newLocation];
// test the age of the location measurement to determine if the measurement is cached
// in most cases you will not want to rely on cached measurements
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;
// test that the horizontal accuracy does not indicate an invalid measurement
if (newLocation.horizontalAccuracy < 0) return;
// test the measurement to see if it is more accurate than the previous measurement
if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy) {
// store the location as the "best effort"
self.bestEffortAtLocation = newLocation;
// test the measurement to see if it meets the desired accuracy
//
// IMPORTANT!!! kCLLocationAccuracyBest should not be used for comparison with location coordinate or altitidue
// accuracy because it is a negative value. Instead, compare against some predetermined "real" measure of
// acceptable accuracy, or depend on the timeout to stop updating. This sample depends on the timeout.
//
if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
// we have a measurement that meets our requirements, so we can stop updating the location
//
// IMPORTANT!!! Minimize power usage by stopping the location manager as soon as possible.
//
[self stopUpdatingLocation:NSLocalizedString(#"Acquired Location", #"Acquired Location")];
// we can also cancel our previous performSelector:withObject:afterDelay: - it's no longer necessary
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:#selector(stopUpdatingLocation:) object:nil];
}
}
// update the display with the new location data
}
The credit goes to Apple because this is a snippet straight from their sample code LocateMe:
http://developer.apple.com/library/ios/#samplecode/LocateMe/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007801-Intro-DontLinkElementID_2
So when you get the notification and need to get a better result you'll need to update the accuracy and see if that gives you a better result.
I'm starting with geocoding. And I have a lot of doubts.
I'm able to do forward and reverse geocoding (I guess, its not perfect).
And now, I'm trying to detect if user (device) enters or leaves a region. For that, I picked up apple's sample code "Regions". The sample uses regionMonitoring. I already try it in a device, but its not working well. I set a region with 25 meters radius, and when I left the region (walking) doesn't happen anything.
My question is: there is another and better way of doing this, detect if user enters or leaves a region, than regionMonitoring?
Can someone help me here??
Thanks a lot.
you could keep the user-location tracking running in the background (here is a good tutorial) but keep in mind this can be heavier on battery use than regionMonitoring.
I found a solution to calculate the distance between two CLLocationCoordinate2D it is easier than I though:
- (CLLocationDistance) DistanceBetweenCoordinate:(CLLocationCoordinate2D)originCoordinate andCoordinate:(CLLocationCoordinate2D)destinationCoordinate {
CLLocation *originLocation = [[CLLocation alloc] initWithLatitude:originCoordinate.latitude longitude:originCoordinate.longitude];
CLLocation *destinationLocation = [[CLLocation alloc] initWithLatitude:destinationCoordinate.latitude longitude:destinationCoordinate.longitude];
CLLocationDistance distance = [originLocation distanceFromLocation:destinationLocation];
[originLocation release];
[destinationLocation release];
return distance;
}
I am writing an app, that uses GPS. I can get successfully the latitude, longitude and other properties, but altitude seems to always return "0.00" i have the following code to test it in the most simplest way and still get 0.00. Code below:
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
// Stop updating location if renewed in less than 60 seconds
if ([self timeBetweenLocationandNow] < 60)
{
[locationManager stopUpdatingLocation];
NSLog(#"GPS Stopped");
}
NSLog(#"Altitude:%.2f m",newLocation.altitude);
}
Any ideas on what could be wrong ? also on an init method i have the following:
- (id)init
{
self = [super init];
if (self != nil)
{
// Create location manager Object
locationManager = [[CLLocationManager alloc] init];
// Set the delegate to this object
[locationManager setDelegate:self];
// Set distance filter and accuracy
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
}
return self;
}
Will appreciate any insight. thank you
I'm no expert but this is how I understand it: The iPhone is quite different from other gps systems because of the multiple ways in which it goes about figuring out your location. The iPhone figures out the location in three ways: local wifi signals, cell towers, and/or gps chip. Using a gps satellite to find a position can be extremely slow and reception can be pretty much non-existent in populated cities. Therefore, iPhone generally looks to the first 2 options first.
Wifi positioning data comes from people driving around on the streets logging hotspots which obviously isn't going to give much of a hint of an altitude. I'm not sure if cell tower triangulation gives any altitude data but my guess is no. These two methods are extremely fast compared to gps but will yield an altitude of 0 as you have seen. If you are in a place where there is a decent gps satellite reception the iPhone may give you the altitude, but even then, it might not even find it till it has received the satellite signal a few times and called the location delegate multiple times, and even then altitude data for gps can be notoriously inaccurate.
Long story short, it's a bad idea to count on accurate altitude data from the iPhone.
i found the problem. As Deepmist suggested the delegate has to be called several times. I was stopping the GPS after the first fix. Which was giving me accurate data for coordinates but altitude remained # 0.00 until like 3 or so delegate calls. Now i get the altitude data, what is a good way to check for this ? so i can stop the location manager after i get the data ? i can check that altitude is a non-zero value, but was wondering if there are other properties that should be used instead to make sure that you have the highest accuracy possible making all of your location data valid (i.e non-zero on some properties). thank you