只是关于核心位置的一个快速问题,我正在尝试计算两点之间的距离,代码如下:

    -(void)locationChange:(CLLocation *)newLocation:(CLLocation *)oldLocation
    {

    // Configure the new event with information from the location.
        CLLocationCoordinate2D newCoordinate = [newLocation coordinate];
        CLLocationCoordinate2D oldCoordinate = [oldLocation coordinate];

        CLLocationDistance kilometers = [newCoordinate distanceFromLocation:oldCoordinate] / 1000; // Error ocurring here.
        CLLocationDistance meters = [newCoordinate distanceFromLocation:oldCoordinate]; // Error ocurring here.
}

我在最后两行收到以下错误:



我一直在搜索Google,但找不到任何东西。

最佳答案

尝试以下方法:

CLLocationDistance meters = [newLocation distanceFromLocation:oldLocation];

您尝试使用的方法是CLLocation对象上的方法:)

关于ios - distanceFromLocation-计算两点之间的距离,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3905896/

10-09 09:41