【问题标题】:Objective C - iPhone comparing 2 CLLocations /GPS coordinatesObjective C - iPhone 比较 2 个 CLLocations /GPS 坐标
【发布时间】:2010-03-21 11:55:04
【问题描述】:

好的,多亏了 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 的数字都假定不匹配。

【问题讨论】:

    标签: iphone objective-c xcode gps cllocation


    【解决方案1】:

    是的,您可以使用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.
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-19
      • 2014-08-06
      • 1970-01-01
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 2015-07-12
      • 1970-01-01
      相关资源
      最近更新 更多