-1

I'm comparing the coordinates of a location to the current coords of a user. The distance is outputted like: 6056609.511004132946254686

I'm not sure what measurement this is in. I want the final measured distance to be in km.

 // location of deal
CLLocation *locA = [[CLLocation alloc] initWithLatitude:latNum longitude:lngNum];

// user's current location
CLLocation *locB = [[CLLocation alloc] initWithLatitude:currentLatitude longitude:currentLongitude];

CLLocationDistance distanceToDeal = [locA distanceFromLocation:locB];
iDev
  • 23,310
  • 7
  • 60
  • 85
hanumanDev
  • 6,592
  • 11
  • 82
  • 146
  • 1
    for what reason was this downvoted? – Alex Gordon Dec 27 '12 at 16:10
  • 1
    @АртёмЦарионов -1 because it's a textbook example of "this question does not show any research effort". If you pull up the help on this method, there is a one sentence description of the return code: "The distance (in meters) between the two locations." It couldn't be more clear. People should read the documentation before posting questions. – Rob Dec 27 '12 at 16:35

3 Answers3

4

The most cursory read of the documentation would have made this clear. If you turn on the Quick Help Inspector (in Xcode 4.5, press command+option+2 or select "Show Quick Help Inspector" from the "Utilities" section of the "View" menu), and then click on distanceFromLocation in your code, it gives you the documentation for this method right there, which makes it clear that it's in meters. Alternatively, hold the option key as you move your mouse over the distanceFromLocation method in your code, and then click (while still holding down the option key) you'll see an online help popover.

Before you post a question here, you really should look at the Apple documentation.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
2

In meters, from Apple documentation:

CLLocationDistance

A distance measurement (in meters) from an existing location.

typedef double CLLocationDistance

Availability Available in iOS 2.0 and later. Declared In CLLocation.h

pablasso
  • 2,479
  • 2
  • 26
  • 32
iArezki
  • 1,273
  • 2
  • 17
  • 29
2

As described in the Apple doc the distanceFromLocation function return value in meters. So the thing you have to do is to convert meters to km ;)

CLLocation *locA = [[CLLocation alloc] initWithLatitude:latNum longitude:lngNum];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:currentLatitude longitude:currentLongitude];

//Compute distance in meters
CLLocationDistance distanceToDeal = [locA distanceFromLocation:locB];

//Convert meters to km
double km = distanceToDeal/1000;
Ashbay
  • 1,641
  • 13
  • 20