CLLocation - 在另一个位置找到磁偏角/偏差

Ste*_*owe 7 iphone objective-c cllocation ios

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

我想做的是能够将一个销钉放在地图上的某个位置,并从该点找到具有磁性变化的真实轴承和轴承.

谢谢!

Chr*_*bbs 5

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

如果有人能找到该代码或发布世界磁模型的目标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
Run Code Online (Sandbox Code Playgroud)


Tíb*_*íbó 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;
}
Run Code Online (Sandbox Code Playgroud)