feat: (broken) implement route map and address autocomplete widgets with associated infrastructure testing scripts
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
const encoded = "qospGlrrB";
|
||||
|
||||
function safeDecodePolyline(encoded) {
|
||||
let index = 0, len = encoded.length;
|
||||
let lat = 0, lng = 0;
|
||||
const poly = [];
|
||||
|
||||
while (index < len) {
|
||||
let b, shift = 0, result = 0;
|
||||
do {
|
||||
if (index >= len) break;
|
||||
b = encoded.charCodeAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
let dlat = ((result & 1) !== 0 ? ~(result >> 1) : (result >> 1));
|
||||
lat += dlat;
|
||||
|
||||
shift = 0;
|
||||
result = 0;
|
||||
do {
|
||||
if (index >= len) break;
|
||||
b = encoded.charCodeAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
let dlng = ((result & 1) !== 0 ? ~(result >> 1) : (result >> 1));
|
||||
lng += dlng;
|
||||
|
||||
poly.push([lat / 1e5, lng / 1e5]);
|
||||
}
|
||||
return poly;
|
||||
}
|
||||
|
||||
const pts = safeDecodePolyline(encoded);
|
||||
console.log("Decoded", pts.length, "points.");
|
||||
for(let i=0; i<5 && i<pts.length; i++) {
|
||||
console.log(pts[i]);
|
||||
}
|
||||
if(pts.length > 5) {
|
||||
console.log("...");
|
||||
for(let i=pts.length-5; i<pts.length; i++) {
|
||||
console.log(pts[i]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user