计算mapcenter,使移动注释(gps)保持在屏幕上的可见视图中

时间:2014-10-03 12:58:16

标签: ios mkmapview cllocation cllocationcoordinate2d

我的计算有点问题。

我想要的是应用程序的用户将移动的地图注释定位在地图的可见区域中的某个位置。虽然注释位置正在改变(gps单位),但地图应该移动但是引脚始终保持在屏幕中的那个点。

我正在尝试使用this stackoverflow answer

的结果

的结果
-(CLLocationDistance) calcluateDistance:(CLLocationCoordinate2D)annotationLocation{

CLLocation *annotationPosition = [[[CLLocation alloc]initWithLatitude:annotationLocation.latitude longitude:annotationLocation.longitude]autorelease];
CLLocation *centrePosition = [[CLLocation alloc]initWithLatitude:self.mapView.centerCoordinate.latitude longitude:self.mapView.centerCoordinate.longitude];
CLLocationDistance distance = [centrePosition distanceFromLocation:trackerPosition];
return distance;

}

并将结果投入this stackoverflow anser

有些事情并没有真正起作用。我知道我的解释不是很清楚所以请问我是否有任何不清楚的地方:)

谢谢

1 个答案:

答案 0 :(得分:0)

你正在使用的方法的一个问题是距离不能告诉你方向,即距离40米但是它的距离是40米还是西方?

对您有用的一个功能是[mapView convertPoint:annotationPoint toCoordinateFromView:mapView]

如果您计算相对于注释应该保留的地图视图的点,请存储此值,并使用[mapView convertPoint:annotationPoint toCoordinateFromView:mapView]来计算地图视图中的坐标。

希望它有所帮助。