-
Notifications
You must be signed in to change notification settings - Fork 0
/
LatLng_offsets.js
95 lines (82 loc) · 3.13 KB
/
LatLng_offsets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
Generates a list of distances between
(1) the LatLng coordinates recorded in local memory for the location, and
(2) the LatLng coordinates in the panorama metadata pulled from Google,
for locations with a locked panoID.
This is needed to guide the determination of a threshold to detect
whether an imported location has likely had its LatLng coordinates
manually changed.
*/
let famous = [];
// let i_made_this_smile = [];
// const HALF_PI = Math.PI / 2;
const DEG_TO_RAD = Math.PI / 180;
async function record_distances(loc_local) {
await svs.getPanoramaById(loc_local.panoId).then(
(response) => {
const loc_goog = response.data.location;
const lat1 = loc_local.lat * DEG_TO_RAD,
lat2 = loc_goog.latLng.lat() * DEG_TO_RAD,
diff_lng = (loc_local.lng - loc_goog.latLng.lng()) * DEG_TO_RAD;
/*
Haversine distance formula from Wikipedia, derived by taking
the dot product in 3D. Stability for close-by points
should be good per theory.
*/
const d_hav = 2 * Math.asin(
Math.sqrt(
Math.sin((lat1 - lat2) / 2) ** 2 + Math.cos(lat1) * Math.cos(lat2) * Math.sin((diff_lng) / 2) ** 2
)
);
famous.push({
unitSphereDistance: d_hav,
sphericalEarthDistance: d_hav * 6371009,
loc: loc_local
});
/*
Attempt at a distance formula using 3D rotations instead.
Bad stability because for two close-by points we would be
evaluating asin of an input very close to 1.
*/
// const zen1 = HALF_PI - lat1;
// const d_i_made_this_smile = HALF_PI - Math.asin(
// Math.sin(zen1) * Math.cos(lat2) * Math.cos(diff_lng) + Math.cos(zen1) * Math.sin(lat2)
// );
// i_made_this_smile.push([
// d_i_made_this_smile,
// d_i_made_this_smile * 6371009,
// loc_local
// ]);
}
);
}
function generateDistancesList() {
const locsIterator = locs.values();
let progressCounter = 0;
/*
Use multiple tasks, since waiting for the server response is
the biggest time sink here
*/
const numParallelTasks = 4;
let tasksDoneCounter = 0;
for(let i = 0; i < numParallelTasks; i++) checkNextLocTask();
async function checkNextLocTask() {
let nextResult = locsIterator.next();
while(!nextResult.done) {
progressCounter++;
const loc_local = nextResult.value;
if(loc_local.panoId) {
await record_distances(loc_local);
console.log(famous.length, `(${progressCounter}/${locs.size})`);
}
nextResult = locsIterator.next();
}
if(++tasksDoneCounter == numParallelTasks) {
famous.sort(
(a, b) => a.unitSphereDistance - b.unitSphereDistance
);
console.log(famous);
}
}
}
generateDistancesList();