0

我正在为我最新的 iOS 5 应用程序编写自定义注释视图,我正在寻找最新的 SDK 友好方式来比较 2 个 CLLocationCoordinate2D 坐标?

CLLocationCoordinate2D coordinate = (CLLocationCoordinate2D){33.0,-112.4};
CLLocationCoordinate2D coordinate = (CLLocationCoordinate2D){33.0,-112.3};

有没有内置的方法来确定这样的事情?

4

1 回答 1

2

您不需要内置方法。您只需要比较纬度

CLLocationCoordinate2D coordinate1 = (CLLocationCoordinate2D){33.0,-112.4};
CLLocationCoordinate2D coordinate2 = (CLLocationCoordinate2D){34.0,-112.3};

CLLocationCoordinate2D furthestNorth;
if (coordinate1.latitude > coordinate2.latitude) {
    furthestNorth = coordinate1;
} else {
    furthestNorth = coordinate2;
}
// OR
furthestNorth = (coordinate1.latitude > coordinate2.latitude) ? coordinate1 : coordinate2;
于 2012-05-17T01:09:11.110 回答