Created
September 15, 2021 01:15
-
-
Save dfellis/6b2415a8215177100bc4c0ae98fb9515 to your computer and use it in GitHub Desktop.
Remote Execution Third Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const degsToRads = (deg) => Math.PI / 180 * deg; | |
const haversine = (origin, dest) => Math.acos( | |
Math.sin(degsToRads(origin.lat)) * Math.sin(degsToRads(dest.lat)) + | |
Math.cos(degsToRads(origin.lat)) * Math.cos(degsToRads(dest.lat)) * Math.cos(degsToRads(dest.lng - origin.lng)) | |
); | |
const notablePlaces = await query(`select * from notablePlaces`); | |
const relevantPlaces = notablePlaces | |
.map((p) => ({ | |
name: p.name, | |
img: p.img, | |
desc: p.desc, | |
distance: haversine({ | |
lat: p.lat, | |
lng: p.lng, | |
}, { | |
lat: trip.destLat, | |
lng: trip.destLng, | |
}), | |
})) | |
.sort((a, b) => b.distance - a.distance) | |
.slice(0, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment