Zeeshan Anjum
Zeeshan Anjum

Reputation: 148

Calculating Distance between two coordinates using CLLocation is different on two phones?

I am calculating distance between two coordinates using CoreLocation framework, one being current location of the user and the other coming from the server, both phones are showing a difference of approx. 25 meters in distance when the phones were right next to each other. I was using iPhone 4s and iPhone 5s, is this has something to do with the accuracy of GPS modules installed on both phones or something is wrong with my implementation?

CLLocationDistance distance = [newLocation distanceFromLocation:userLocation];

Upvotes: 0

Views: 247

Answers (1)

7vikram7
7vikram7

Reputation: 2824

Neither a handheld GPS or smart phone receiver will give you an exact position. At best you'll get an accuracy of about 10 to 15 feet (3 to 5 meters). If you are under trees or surrounded by tall buildings then you can expect an accuracy of 20 to 30 feet (6 to 10 meters) or even worse. Only professional GPS devices as used by surveyors can give accuracy to under one inch (2cm) https://support.groundspeak.com/index.php?pg=kb.page&id=673

The accuracy also depends on the kind of cellular/wifi network you are using for your phone. I have experienced that the accuracy of the locations obtained on wifi networks is far greater than when you are on cellular data.

Also when you get a location update in the following delegate of CLLocationManager:-

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
{
}

Investigate the 'horizontalAccuracy' of the new location which you get (newLocation.horizontalAccuracy). It is the error in meters, which the coordinates might have.

/*
 *  horizontalAccuracy
 *  
 *  Discussion:
 *    Returns the horizontal accuracy of the location. Negative if the lateral location is invalid.
 */
@property(readonly, nonatomic) CLLocationAccuracy horizontalAccuracy;

Hope it helps.

Upvotes: 1

Related Questions