Published
Edited
Jul 7, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
seed = +d3.timeDay.floor(new Date())
Insert cell
place = d3.shuffler(d3.randomLcg(seed))(places.slice(0))[0]
Insert cell
places = results.filter(d => d.rating >= 3).sort((a, b) => d3.descending(a.id, b.id))
Insert cell
Math.sqrt(area) / 2
Insert cell
results = {
let results = [];
let n = 0;
while (true) {
const page = await search(category, n);
results = results.concat(page.businesses);
if (results.length >= page.total) break;
if (n++ > 10) break;
}
return results;
}
Insert cell
Insert cell
categories = (
await (
await fetch(
`https://cors-proxy.visnup.vercel.app/api.yelp.com/v3/categories`,
{
headers: { authorization: `Bearer ${yelpKey}` }
}
)
).json()
).categories.map((d) => d.alias)
Insert cell
// Docs: https://www.yelp.com/developers/documentation/v3/business_search
yelpKey = "n4MdpSiiFKFAukCljMUheeOWjBXygRXSXGsCyuVqJnhxv3yXwOzPXKXWhClXIenujoNRRDP1nMHFwHUxN6Gm1g872bDyGT3k5UWyDGvSyQawYPz9jXnESXjWLP_kYHYx"
Insert cell
// Docs: https://developers.google.com/maps/documentation/embed/map-generator
gmapsKey = "AIzaSyBz_sOVfuXMJsi5YLkNW0SJv3VqklumDAc"
Insert cell
// Adapted from https://www.johndcook.com/how_big_is_a_degree.html. All lengths in miles. This is only approximate, because it assumes the area is small relative to the surface of the earth, and treats it as rectangular, which it totally isn’t. That sloppiness is of course mine (Toph’s), not John D. Cook’s.
area = {
const { latitude, longitude } = yourLocation;
const unit = 1 / 10 ** precision;

// "A degree of latitude, one degree north or south, is about the same distance anywhere"
const latLength = 69;

// Compute spherical coordinates to find length of one degree of longitude
const earthCircumference = 24902.0;
const longLength =
(Math.cos((latitude * Math.PI) / 180.0) * earthCircumference) / 360.0;

return latLength * longLength * unit ** 2;
}
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