7

我知道如何找到我的手机当前所在位置的真实航向/磁航向,但是否可以找到远程位置的磁偏角/磁偏角?

我想做的是能够在地图上的某个地方放一个大头针,然后从该点找到真正的方位和具有磁性变化的方位。

谢谢!

4

3 回答 3

5

计算它的代码必须已经存在于某个框架中,因为它在位置服务可用时由 CLHeading 使用。

如果有人能找到该代码或拥有用于发布世界磁模型的 Objective C,将不胜感激。

更新:我发现了一个很棒的开源 iOS 包装器!谢谢曲颈! https://github.com/stephent/ObjectiveWMM

作为 git 子模块的简单安装

run this command:
$git submodule add https://github.com/stephent/ObjectiveWMM.git ObjectiveWMM

Add these files to your Xcode project:
CCMagneticDeclination.h
CCMagneticDeclination.m
CCMagneticModel.h
CCMagneticModel.m
NSDate+DecimalYear.h
NSDate+DecimalYear.m
WMM/EGM9615.h
WMM/GeomagnetismHeader.h
WMM/GeomagnetismLibrary.c
WMM/WMM.COF
于 2014-01-25T00:05:39.933 回答
4

你解决了吗?否则,您可以计算远程位置的方位角。首先是磁北航向,然后是真北航向。最后将两者相减得到磁偏差。

以下是如何计算远程位置的方位角:

-(float)azimuthFromLocations:(CLLocationCoordinate2D)first toCoordinate:(CLLocationCoordinate2D)second{
float longitudeDifference = second.longitude - first.longitude;
float latitudeDifference = second.latitude  - first.latitude;
float possibleAzimuth = (M_PI * .5f) - atan(latitudeDifference / longitudeDifference);

if (longitudeDifference > 0)
    return possibleAzimuth;
else if (longitudeDifference < 0)
    return possibleAzimuth + M_PI;
else if (latitudeDifference < 0)
    return M_PI;

return 0.0f;
}
于 2012-11-14T22:44:17.947 回答
1

我需要在 Swift 中基于 World Magnetic Model 的相同解决方案。

这是我的实现: https ://github.com/kanchudeep/Geomagnetism-Swift

这是一个简单的单一类,可以放入任何项目并使用。

于 2017-12-11T09:34:50.257 回答