代码之家  ›  专栏  ›  技术社区  ›  Sukeshj

使用经纬度计算到位置的距离

  •  1
  • Sukeshj  · 技术社区  · 14 年前

    在我的应用程序中,当用户拨号或接收呼叫时,我正在收集纬度和经度,此时我正在用nstimer调用一个延迟15秒的函数,然后再次收集纬度和经度。

    问题是,当我计算它们之间的距离时,即使我不移动,它也会给出0.87英里或1英里的最小距离。 我用了下面的公式

    double    distance = (sin(gpslatitudeOld/57.2958) * sin(gpslatitudeNew/57.2958)) + (cos(gpslatitudeOld/57.2958) * cos(gpslatitudeNew/57.2958) * cos(gpslongitudeNew/57.2958 - gpslongitudeOld/57.2958));
    

    从现场 (http://www.meridianworlddata.com/distance-calculation.asp)

    我也用过

    [新位置获取距离:开始点]

    但还是没有得到其他的结果,在一个论坛里,我读到经度和纬度都是1英里。 有没有解决办法????

    3 回复  |  直到 14 年前
        1
  •  1
  •   TomH    14 年前
        2
  •  3
  •   sinh99    13 年前
    CLLocation *location1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
    CLLocation *location2 = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
    NSLog(@"Distance i meters: %f", [location1 distanceFromLocation:location2]);
    [location1 release];
    [location2 release];
    
        3
  •  0
  •   T.E.D.    14 年前