如何绘制围绕中心坐标相对于设备旋转的真实世界坐标?

时间:2013-01-14 22:39:57

标签: iphone ios gps core-location

我正在开发一款简单的位置感知游戏,用户的当前位置显示在游戏地图上,以及周围其他玩家的位置。它不是使用MKMapView而是使用没有街道的自定义游戏地图。

如何将其他玩家的其他纬度/经度坐标转换为CGPoint值,以在50米= 50点的固定比例的世界比例游戏地图中表示它们,并定位所有点以便用户可以看出他必须去哪个方向去接触另一个球员?

关键目标是为平面自上而下的视图生成纬度/经度坐标的CGPoint值,但是将点定位在用户当前位置周围,类似于Google地图的方向图功能(箭头),这样您就知道了是什么。

是否有进行计算的框架?

2 个答案:

答案 0 :(得分:3)

首先你必须将lon / lat转换为笛卡尔x,y,以米为单位 接下来是与其他玩家的度数方向。方向是dy / dx,其中dy = player2.y到me.y,dx相同。通过除以playerv2和我之间的距离来将dy和dx标准化为此值。 你收到

ny = dy / sqrt(dx*dx + dy*dy)
nx = dx / sqrt(dx*dx + dy*dy)

乘以50.现在你在玩家2的方向上有一个50米的位置:

comp2x = 50 * nx;
comp2y = 50 * ny;

现在将地图置于me.x / me.y中心。并将屏幕应用于仪表刻度

答案 1 :(得分:2)

你想从MapKit获得MKMapPointForCoordinate。这将纬度 - 经度对转换为由x和y定义的平面。请查看描述投影的MKMapPoint文档。然后,您可以根据显示需要将这些x,y对缩放并旋转到CGPoints中。 (您必须尝试查看哪些缩放因子适用于您的游戏。)

要使用户周围的点居中,只需从所有其他对象的点中减去x和y位置(在MKMapPoints中)的值。类似的东西:

MKMapPoint userPoint = MKMapPointForCoordinate(userCoordinate);
MKMapPoint otherObjectPoint = MKMapPointForCoordinate(otherCoordinate);

otherObjectPoint.x -= userPoint.x; // center around your user
otherObjectPoint.y -= userPoint.y;

CGPoint otherObjectCenter = CGPointMake(otherObjectPoint.x * 0.001, otherObjectPoint.y * 0.001);

// Using (50, 50) as an example for where your user view is placed.
userView.center = CGPointMake(50, 50);
otherView.center = CGPointMake(50 + otherObjectCenter.x, 50 + otherObjectCenter.y);