我正在为我最新的iOS 5应用编写自定义注释视图,我正在寻找最新的SDK友好方式来比较2个CLLocationCoordinate2D坐标?
CLLocationCoordinate2D coordinate = (CLLocationCoordinate2D){33.0,-112.4};
CLLocationCoordinate2D coordinate = (CLLocationCoordinate2D){33.0,-112.3};
是否有内置的方法来确定这样的东西?
答案 0 :(得分:2)
您不需要内置方法。您只需要比较latitude:
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;