Skip to content

Instantly share code, notes, and snippets.

@jamigibbs
Last active June 19, 2018 18:17
Show Gist options
  • Save jamigibbs/f091b1043f5551c6e5c6b8f8d71910fd to your computer and use it in GitHub Desktop.
Save jamigibbs/f091b1043f5551c6e5c6b8f8d71910fd to your computer and use it in GitHub Desktop.
export const getNearestDivvyStation = (lat, lng) => {
const url = `${GOOGLE_PLACES_URL}?location=${lat},${lng}&radius=1000&type=point_of_interest&keyword=divvy&key=${API_KEY}`
return async (dispatch) => {
const { data } = await axios.get(url)
const current = {lat, lng}
const closest = data.results.map((station) => {
const coord = station.geometry.location
return { coord, dist: geolib.getDistance(current, coord) }
})
.sort( (a, b) => a.dist - b.dist )[0]
dispatch(gotNearestDivvyStation(closest))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment