Objective c 在MKMapView上叠加问题
我已经设置了一个Objective c 在MKMapView上叠加问题,objective-c,ios,xcode,mkmapview,cllocation,Objective C,Ios,Xcode,Mkmapview,Cllocation,我已经设置了一个CLLocation对象,我正在添加MKCircle覆盖。我希望MKCircle的radius变量与以下两个变量相关: 地图视图的大小 位置的大小 那么,如何从CLLocation中检索某种大小值呢?更好的是,一旦我与地图视图交互/缩小,它会自动缩放吗?以下是我的目标概述: 将覆盖添加到地图视图。覆盖将位于CLLocationCLLocationCoordinate2D变量处,但我希望覆盖适合该位置的大小,然后在使用地图进行放大和缩小后调整大小,我很确定它应该自动执行此操作。我知
CLLocation
对象,我正在添加MKCircle
覆盖。我希望MKCircle
的radius
变量与以下两个变量相关:
CLLocation
中检索某种大小值呢?更好的是,一旦我与地图视图交互/缩小,它会自动缩放吗?以下是我的目标概述:
将覆盖添加到地图视图。覆盖将位于CLLocation
CLLocationCoordinate2D
变量处,但我希望覆盖适合该位置的大小,然后在使用地图进行放大和缩小后调整大小,我很确定它应该自动执行此操作。我知道我需要定义MKCircle
的半径变量,但是我应该如何设置它?你们知道我怎么做吗
谢谢
更新:
CLLocation *org = [[CLLocation alloc] initWithLatitude:coordO.latitude longitude:coordO.longitude];
CLLocation *des = [[CLLocation alloc] initWithLatitude:coordD.latitude longitude:coordD.longitude];
MKCircle *myCircle = [MKCircle circleWithCenterCoordinate:coordO radius:org.horizontalAccuracy];
MKCircle *myCircle2 = [MKCircle circleWithCenterCoordinate:coordD radius:des.horizontalAccuracy];
if (myCircle2 && myCircle) {
NSLog(@"destination and origin both valid");
}
[mapView addOverlays: [NSArray arrayWithObjects:myCircle, myCircle2, nil]];
[myCircle setTitle:@"Placeholder"];
[myCircle2 setTitle:@"Placeholder"];
[localOverlays addObjectsFromArray: [NSArray arrayWithObjects:myCircle, myCircle2, nil]];
这是我用来向地图视图添加覆盖的全部代码,尽管它不起作用,但覆盖(
MKCircle
,我认为它是一个圆)不存在/不可见。我查看了HazardMap Apple示例代码,看起来他们为安装程序创建了一些其他类。这是必要的,我的代码有什么问题。谢谢 mk圆的半径是一个CLLocationDistance
,表示以米为单位的距离测量值。
CLLocation
的水平精度为CLLocation精度
,表示以米为单位的坐标值的精度
因此,您需要做的就是:
MKCircle *circle = [MKCircle circleWithCenterCoordinate:location.coordinate
radius:location.horizontalAccuracy];
更新:覆盖图不可见,因为您手动创建了位置,因此其水平精度为零。您可以使用方法-[CLLocation initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:timestamp://创建具有自定义水平精度的CLLocation
。或者您可以定义圆的最小半径(例如10米):
mk圆的半径是cl定位距离
,表示以米为单位的距离测量值。
CLLocation
的水平精度为CLLocation精度
,表示以米为单位的坐标值的精度
因此,您需要做的就是:
MKCircle *circle = [MKCircle circleWithCenterCoordinate:location.coordinate
radius:location.horizontalAccuracy];
更新:覆盖图不可见,因为您手动创建了位置,因此其水平精度为零。您可以使用方法-[CLLocation initWithCoordinate:altitude:horizontalAccuracy:verticalAccuracy:timestamp://创建具有自定义水平精度的CLLocation
。或者您可以定义圆的最小半径(例如10米):
谢谢你,尼古拉斯,我能快点问你一个问题吗?我有一些代码添加了一个MKCircle覆盖,如我更新的答案所示。如果你能回答,我将不胜感激。谢谢尼古拉斯,我能很快问你一个问题吗?我有一些代码添加了一个MKCircle覆盖,如我更新的答案所示。如果你能回答,我将不胜感激。