I know how to find the true heading/magnetic heading for the location my phone is currently at, but is it possible to find the magnetic deviation/declination for a remote location?
What I would like to do is be able to drop a pin at a place on the map and find both the true bearing and the bearing with magnetic variance from that point.
Thanks!
The code to calculate this must already exist in a framework somewhere since it's used by CLHeading when location services are available.
If anyone can find that code or has Objective C for the world magnetic model posting it would be appreciated.
UPDATE: I found a great open source iOS wrapper! Thanks Crookneck! https://github.com/stephent/ObjectiveWMM
Simple installation as a git submodule
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
Have you solved it? Otherwise you can calculate the azimuth angle of the remote location. Firstly with magnetic north heading and then with true north heading. Finally you subtract the two to get the magnetic deviation.
Here is how to calculate an azimuth angle for a remote location:
-(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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With