UNPKG

zland-core

Version:
35 lines (31 loc) 1.1 kB
/*! * Copyright 2015 Florian Biewald * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 'use strict'; function rad(x) { return x * Math.PI / 180; }; module.exports = { calculateMeters: function(p1, p2) { var R, a, c, d, dLat, dLong; R = 6378137; dLat = rad(p2.latitude - p1.latitude); dLong = rad(p2.longitude - p1.longitude); a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(rad(p1.latitude)) * Math.cos(rad(p2.latitude)) * Math.sin(dLong / 2) * Math.sin(dLong / 2); c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); d = R * c; return d; } }