1

好的,多亏了 Claus Broch,我在比较两个 GPS 位置方面取得了一些进展。我需要能够说“如果当前位置等于(列表中的任何 GPS 位置)然后做某事

我目前的代码是:

CLLocationCoordinate2D bonusOne; bonusOne.latitude = 37.331689; bonusOne.longitude = -122.030731;

哪个是 Infinite Loop 的模拟器 GPS 位置

CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:bonusOne.latitude longitude:bonusOne.longitude];
double distance = [loc1 getDistanceFrom:newLocation];
if(distance <= 10000000) {

然后做点什么}

任何低于 10000000 的数字都假定没有匹配项。

4

1 回答 1

2

是的,您可以使用它getDistanceFrom来获取两点之间的距离。距离以米为单位。您可以使用该比较与位置管理器的当前水平精度进行比较,以确定您是否大致处于“奖励一”位置。

CLLocation *bonusLocation = [[CLLocation alloc] initWithLatitude:bonusOne.latitude longitude:bonusOne.longitude];
float distance = [bonusLocation getDistanceFrom:newLocation];
float threshold = 2 * [newLocation horizontalAccuracy]; // Or whatever you like
if(distance <= threshold) {
  // You are at the bonus location.
}
于 2010-03-21T12:03:35.927 回答