MKMapView查找位置并将其显示给用户

时间:2012-09-26 17:05:45

标签: objective-c ios mkmapview

enter image description here

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

当我的应用程序的用户处于半径为1km的红色圆圈时,我的应用程序必须说他在Tour Eiffel。

我该怎么做?我知道我必须找回位置,但在那之后我怎样才能找到距当前位置中心1公里的半径? 感谢

*编辑* 谢谢你我用

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

但如果我不在地图上显示我的位置,那么这段代码就不起作用了。 如果我检查我的位置而不是分享我的位置,那就有效。 如何在没有用户交互的情况下强制应用程序自动获取我的位置? 感谢

1 个答案:

答案 0 :(得分:0)

创建CLRegion。 来自docs:

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.

将center和radius的属性设置为所需的值。调用startMonitoringForRegion:desiredAccuracy。如果需要测试用户的位置而不是使用用户跨越定义区域边界时生成的通知,则CLRegion类有一个containsCoordinate:instance方法。

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