【问题标题】:Detect if user enters or leaves a region - geocoding检测用户是否进入或离开区域 - 地理编码
【发布时间】:2012-01-11 12:58:27
【问题描述】:

我从地理编码开始。我有很多疑问。

我能够进行正向和反向地理编码(我猜,它并不完美)。

现在,我正在尝试检测用户(设备)是否进入或离开某个区域。为此,我选择了苹果的示例代码“Regions”。该示例使用regionMonitoring。我已经在设备中尝试过,但效果不佳。我设置了一个半径为 25 米的区域,当我离开该区域(步行)时不会发生任何事情。

我的问题是:与regionMonitoring相比,还有另一种更好的方法来检测用户是否进入或离开区域?

有人可以帮我吗?

非常感谢。

【问题讨论】:

    标签: iphone ios geolocation core-location


    【解决方案1】:

    您可以让用户位置跟踪在后台运行 (here is a good tutorial),但请记住,这可能比 regionMonitoring 消耗更多电量。

    【讨论】:

    • 感谢它的好教程。但是跟踪用户位置我已经能够做到。关键是,使用用户位置,知道他是否在一个区域或区域,在一个位置附近。
    • 如果知道用户位置,以及目标区域的中心,就不能计算距离吗?
    • 是的,就是这样。没有工具可以做到吗??谢谢
    • 使用公式计算距离很简单:d = sqrt((x2-x1)^2 + (y2-y1)^2),x 和 y 是 gps 经度和纬度或用户和目标。
    • 它给了我不真实的价值!这是显而易见的。你给我的公式是平面坐标。你知道世界是圆的,所以它必须以另一种方式计算(用球坐标,我猜)。如果您有兴趣,请查看此link。还是谢谢
    【解决方案2】:

    我找到了一个计算两个CLLocationCoordinate2D 之间距离的解决方案,但它比我更容易:

    - (CLLocationDistance) DistanceBetweenCoordinate:(CLLocationCoordinate2D)originCoordinate andCoordinate:(CLLocationCoordinate2D)destinationCoordinate {
    
        CLLocation *originLocation = [[CLLocation alloc] initWithLatitude:originCoordinate.latitude longitude:originCoordinate.longitude];
        CLLocation *destinationLocation = [[CLLocation alloc] initWithLatitude:destinationCoordinate.latitude longitude:destinationCoordinate.longitude];
        CLLocationDistance distance = [originLocation distanceFromLocation:destinationLocation];
        [originLocation release];
        [destinationLocation release];
    
        return distance;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-06-01
      • 2013-06-17
      • 1970-01-01
      • 2022-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多