1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 function isPublic(ap) {
7 let result = ap.ssid.indexOf(mask, ap.ssid.length - mask.length);
12 return b.signal - a.signal;
16 return { macAddress: ap.mac, signalStrength: ap.signal };
20 * Shared utility functions for modules dealing with
24 export class LocationHelper {
25 static formatWifiAccessPoints(accessPoints) {
26 return accessPoints.filter(isPublic).sort(sort).map(encode);
30 * Calculate the distance between 2 points using the Haversine formula.
31 * https://en.wikipedia.org/wiki/Haversine_formula
33 static distance(p1, p2) {
34 let rad = x => (x * Math.PI) / 180;
35 // Radius of the earth.
37 let lat = rad(p2.lat - p1.lat);
38 let lng = rad(p2.lng - p1.lng);
41 Math.sin(lat / 2) * Math.sin(lat / 2) +
42 Math.cos(rad(p1.lat)) *
43 Math.cos(rad(p2.lat)) *
47 let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));