Public
Edited
Aug 6, 2023
Insert cell
Insert cell
Insert cell
Insert cell
// bryant park
myLocation = ({
lat: 40.75414841155935,
lon: -73.98177702446924
})
Insert cell
data = [
{
lat:40.75814531,
lon:-73.98554259,
name:"Times Square",
emoji: "🔲"
},
{
lat:40.74901236,
lon:-73.98466276,
name:"Empire State Building",
emoji: "🏢"
},
{
lat:40.75920124,
lon:-73.9786863,
name:"Rockefeller Center",
emoji: "🏢"
},
]
Insert cell
locations = data.map(d => ({...d, dist: getDistanceFromLatLonInKm(
d.lat, d.lon,
myLocation.lat, myLocation.lon
)}))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
// https://stackoverflow.com/questions/18883601/function-to-calculate-distance-between-two-coordinates
function deg2rad(deg) {
return deg * (Math.PI/180)
}
var R = 6371; // Radius of the earth in km
var dLat = deg2rad(lat2-lat1); // deg2rad below
var dLon = deg2rad(lon2-lon1);
var a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2)
;
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // Distance in km
return d;
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more