0

在此处输入图像描述

我知道名为 A 的玫瑰针的位置,就像在图片中一样……现在我想做的是这个。

当我的应用程序的用户在半径为 1 公里的红色圆圈中时,我的应用程序必须说他在埃菲尔铁塔。

我怎样才能做到这一点?我知道我必须检索该位置,但在那之后我如何才能从当前位置的中心寻找 1 公里的半径?谢谢

* 编辑 * 谢谢我正在使用

 if ([region containsCoordinate:self.map.userLocation.coordinate]) {
                    miTrovoIn = street;
                }

但是,如果我不在地图中显示我的位置,则此代码不起作用。如果我检查我的位置而不是分享我的位置,它会起作用。如何在没有用户交互的情况下强制应用自动获取我的位置?谢谢

4

1 回答 1

0

创建一个 CLRegion。来自文档:

The CLRegion class defines a geographical area that can be tracked. When an instance of this class is registered with a CLLocationManager object, the location manager generates an appropriate event whenever the user crosses the boundaries of the defined area.

将中心和半径的属性设置为所需的值。调用 startMonitoringForRegion:desiredAccuracy。如果您需要测试用户的位置而不是使用当用户越过您定义的区域边界时生成的通知,CLRegion 类有一个 containsCoordinate: 实例方法。

double lat = 48.86;
double lng = 2.29;
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(lat, lng);
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate radius:1000.0 identifier:@"your identifier"];

http://developer.apple.com/library/IOs/#documentation/CoreLocation/Reference/CLRegion_class/Reference/Reference.html

于 2012-09-26T17:45:26.203 回答