diff --git a/endpoints/bus/realtime.js b/endpoints/bus/realtime.js index 32277a2b..ee29d38a 100644 --- a/endpoints/bus/realtime.js +++ b/endpoints/bus/realtime.js @@ -1,6 +1,7 @@ var h = require('../../lib/helpers.js'), request = require('request'), - app = require('../../server'); + app = require('../../server'), + isn2wgs = require('isn2wgs'); app.get('/bus/realtime', function(req, res){ var data = req.query; @@ -66,7 +67,7 @@ app.get('/bus/realtime', function(req, res){ route.busses.forEach(function(bus, key){ - var location = h.ISN93_To_WGS84(bus.X,bus.Y), + var location = isn2wgs(bus.X,bus.Y), oneRoute = { 'unixTime': Date.parse(bus.TIMESTAMPREAL)/1000, 'x': location.lat, diff --git a/lib/helpers.js b/lib/helpers.js index b6b146ad..f8b5a094 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -104,49 +104,6 @@ exports.browser = function(){ return browsers[Math.floor(Math.random()*browsers.length)]; } -/** - * Function to change strange icelandic lat and lng points to the real thing - * http://kort.samsyn.is/api/api/v2/Example/Example12.aspx - * http://kort.samsyn.is/api/SiteWatch.aspx?v=2&key=Bus49fVdg - */ -exports.ISN93_To_WGS84 = function(q,p){ - q = parseFloat(q); - p = parseFloat(p); - q=q-500000; - p=p-500000; - var m = Math.pow(Math.sqrt(q*q+Math.pow(2982044.27322585-p,2))/11616778.382033,1.10334624954392); - var o = 1.5707963267949-(2*Math.atan(m)); - var l = o; - var k = 0.0818191913305*Math.sin(l);o=1.5707963267949-2*Math.atan(m*Math.pow(((1-k)/(1+k)),0.04090959566525)); - while(o-l>0.000001){ - l = o; - k = 0.0818191913305*Math.sin(l); - o = 1.5707963267949-2*Math.atan(m*Math.pow(((1-k)/(1+k)),0.04090959566525)) - } - return { - lat:Math.round((o*57.2957795130823)*1000000)/1000000, - lng:Math.round(((((Math.atan(q/(2982044.27322585-p)))*57.2957795130823)/0.90633380084752)-19)*1000000)/1000000 - }; -} - -/** - * Function to change lat and lng points to strange icelandic location points - * //http://kort.samsyn.is/api/api/v2/Example/Example12.aspx - * //http://kort.samsyn.is/api/SiteWatch.aspx?v=2&key=Bus49fVdg - */ -exports.WGS84_To_ISN93=function(l,m){ - l = parseFloat(l); - m = parseFloat(m); - var k=l*0.0174532925199433; - var p=0.0818191913305*Math.sin(k); - var o=11616778.382033*Math.pow(Math.tan(0.785398163397448-(k/2))/Math.pow((1-p)/(1+p),0.04090959566525),0.90633380084752); - var q=(m+19)*0.0158185089469038; - return { - x:Math.round((500000+o*Math.sin(q))*1000)/1000, - y:Math.round((3482044.27322585-o*Math.cos(q))*1000)/1000 - }; -} - /** * Iterates through all members of an object and changes it in place. * Changes all members holding arrays of size 1 and sets them to the single item the array holds.