CLLocationDistance converted from Meters to KM/Miles etc

Discussion in 'iPhone/iPad Programming' started by BNZ1, Apr 1, 2009.

  1. macrumors regular

    Joined:
    Nov 11, 2008
    Location:
    London
    #1
    Hi Guys,

    First off, sorry for asking this if it is as simple as I think it should be..... I was trying really hard to not use the forums on my first app but my time has come.

    Basically I have a database of locations and I am calculating the distance to them to organise them by relative closeness. When I do the CLLocationDistance.... command I get a float value returned in meters - e.g. 111125.113474. I want to convert this to KM (divide by 1000) but for the life of me can not work out how to do this!!!

    Code:
    CLLocationDistance distance = [objectLocation getDistanceFrom:currentLocation];
    NSString *distanceString = [NSString stringWithFormat"@"%f", distance];
    

    This code happily gives me a string with the value 111125.113474 but I cannot work out how to manipulate this string.

    Thank you for your help!! ;)
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Divide by 1000 first, then convert to a string?
     
  3. thread starter macrumors regular

    Joined:
    Nov 11, 2008
    Location:
    London
    #3
    Come here, I am going to kiss you :eek:

    Thanks!
     

Share This Page