0

可能重复:
iPhone 指南针 GPS 方向

嗨,我正在尝试开发一个使用 iPhone 的 GPS 和指南针的应用程序,以便将某种指针指向特定位置(如指南针总是指向北方)。该位置是固定的,无论用户位于何处,我总是需要指针指向该特定位置。我有这个位置的纬度/经度坐标,但不知道如何使用指南针和 GPS 指向那个位置......就像http://www.youtube.com/watch?v=iC0Xn8hY80w这个链接 1: 20' 我已经知道一些程序标题 = atan2( sin(lon2-lon1)*cos(lat2), cos(lat1)*sin(lat2) - sin(lat1)*cos(lat2)*cos(lon2-lon1) ) 然后乘以 180/π 然后加上 360 例如 -(CLLocationDirection)directionToLocationCLLocation *)location {

CLLocationCoordinate2D coord1 = self.coordinate; CLLocationCoordinate2D coord2 = location.coordinate;

CLLocationDegrees deltaLong = coord2.longitude - coord1.longitude; CLLocationDegrees yComponent = sin(deltaLong) * cos(coord2.latitude); CLLocationDegrees xComponent = (cos(coord1.latitude) * sin(coord2.latitude)) - (sin(coord1.latitude) * cos(coord2.latitude) * cos(deltaLong));

CLLocationDegrees 弧度 = atan2(yComponent, xComponent); CLLocationDegrees 度数 = RAD_TO_DEG(弧度) + 360;

返回 fmod(度数,360);我设置了一个箭头,想让箭头旋转。但结果不对。而且它不使用当前标题。我认为它必须使用当前标题与结果相结合来旋转箭头。

所以任何人都可以给我一些解决方案。

4

0 回答 0