Reputation: 5380
I'm using CLLocation mechanism to get coordinates in iPhone. I took an example from "Locate me" example and extended it a little bit. However I'm issuing accuracy problems.
So the question is, is there a way to make iPhone to get location using GPS instead of triangulation antennas?
It would be nice to know if there is a way to improve accuracy when using antennas but the best result I got till now is 65 meters.
Upvotes: 1
Views: 1158
Reputation: 4452
Core location wont give you location data with the datasource. The best way to guarantee location is to look for the date of the CLLocation object you receive, and to check the location horizontal and vertical accuracy. I have worked extensively with core location and I can tell you that if you need accurate location data, the time is a very good indicator of inaccurate information. If i need accurate data, i would disregard data older than 5 seconds.
Upvotes: 0
Reputation: 6803
You aren't really supposed to be trying to control what hardware is getting the location for you. If you want greater accuracy, you can check the accuracy given to you by the CLLocation
and throw it out if it's not what you want.
Alternatively, you can take a bunch of readings and average them with this code I wrote! You pass an array of CLLocation
objects to it and it returns one, averaged location. I use it in one of my apps and it gives great accuracy (usually within a meter if you use >5 locations).
- (CLLocation *) averageLocations: (NSArray *) loci
{
double tempLat=0,tempLong=0,tempAlt=0,tempAccH=0,tempAccV=0,tempCourse=0,tempSpeed=0,tempTime=0;
for (CLLocation *loc in loci)
{
tempLat += loc.coordinate.latitude;
tempLong += loc.coordinate.longitude;
tempAlt += loc.altitude;
tempAccH += loc.horizontalAccuracy;
tempAccV += loc.verticalAccuracy;
tempCourse += loc.course;
tempSpeed += loc.speed;
tempTime += loc.timestamp.timeIntervalSinceReferenceDate;
}
double ratio = (double) loci.count;
CLLocationCoordinate2D tempCoord = CLLocationCoordinate2DMake(tempLat/ratio, tempLong/ratio);
NSDate *tempDate = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:tempTime/ratio];
CLLocation *temp = [[CLLocation alloc] initWithCoordinate:tempCoord
altitude:tempAlt/ratio
horizontalAccuracy:tempAccH/ratio
verticalAccuracy:tempAccV/ratio
course:tempCourse/ratio
speed:tempSpeed/ratio
timestamp:tempDate];
return temp;
}
Upvotes: 5