Magnetic declination in JavaScript / Google Maps

There do appear to be web services supplied by ngdc.noaa.gov.

Have a look at the documentation - http://www.ngdc.noaa.gov/geomag-web/calculators/declinationHelp

E.g.

http://www.ngdc.noaa.gov/geomag-web/calculators/calculateDeclination?lat1=40&lon1=-105.25&resultFormat=xml


They have shard this. For Google maps mashup with source see:-

http://www.bdcc.co.uk/Gmaps/Services.htm


Here is an example in Javascript/jQuery fetching magnetic declination for a certain lat/lon position from http://www.ngdc.noaa.gov.

declination=0;

function setdecl(v){
 console.log("declination found: "+v);
 declination=v;
}

function lookupMag(lat, lon) {
   var url=
"http://www.ngdc.noaa.gov/geomag-web/calculators/calculateIgrfgrid?lat1="+lat+"&lat2="+lat+"&lon1="+lon+"&lon2="+lon+
"&latStepSize=0.1&lonStepSize=0.1&magneticComponent=d&resultFormat=xml";
   $.get(url, function(xml, status){
        setdecl( $(xml).find('declination').text());
   });
}

lookupMag(55.58552,12.1313);

For some reason they are using an internal redirect to a HTTP based server, so you cannot use this from a secure site like JSFiddle, but this one worked on codepen.io a couple of hours ago.