检测用户是否进入或离开地区 - 地理编码 [英] Detect if user enters or leaves a region - geocoding

查看:67
本文介绍了检测用户是否进入或离开地区 - 地理编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm starting with geocoding. And I have a lot of doubts.

我可以做前进和后退地理编码(我想,它不完美)。

I'm able to do forward and reverse geocoding (I guess, its not perfect).

现在,我试图检测用户(设备)是否进入或离开某个区域。为此,我拿起苹果的示例代码地区的。该示例使用 regionMonitoring 。我已经在一台设备上尝试过了,但它运行不正常。我设置了一个半径25米的地区,当我离开这个地区时(行走)不会发生任何事情。

And now, I'm trying to detect if user (device) enters or leaves a region. For that, I picked up apple's sample code "Regions". The sample uses regionMonitoring. I already try it in a device, but its not working well. I set a region with 25 meters radius, and when I left the region (walking) doesn't happen anything.

我的问题是:还有另一种更好的方式这样做,检测用户是否进入或离开地区,比 regionMonitoring

My question is: there is another and better way of doing this, detect if user enters or leaves a region, than regionMonitoring?

有人可以帮我吗?

非常感谢。

推荐答案

两个 CLLocationCoordinate2D 之间的距离比我更容易:

I found a solution to calculate the distance between two CLLocationCoordinate2D it is easier than I though:

- (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;
}

这篇关于检测用户是否进入或离开地区 - 地理编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆