I am working on a bike-sharing application where I have the following requirements.
Show all bikes near the user locations in a certain radius.
For this I came with an approach where get all indexes of bike locations on a specific resolution and get all the indexes from the user location with a radius using kRing function and then find all the bike locations which are inside kRing indexes.
const res = 8;
//get hexagon index of all locations
const lookupMap = bike_locations.reduce((map, bike) => {
const {latitude, longitude} = bike;
const h3Index = h3.geoToH3(latitude, longitude, res);
if (!map[h3Index]) map[h3Index] = [];
map[h3Index].push(bike.id);
return map;
}, {});
//hexagon index of user location
const origin = h3.geoToH3(user_lat, user_logn, res);
const radius = Math.floor(distance_in_km / (h3.edgeLength(res, h3.UNITS.km) * 2));
const lookupIndexes = h3.kRing(origin, radius);
// Find all points of bikes in those indexes
const results = lookupIndexes.reduce(
(output, h3Index) => [...output, ...(lookupMap[h3Index] || [])],
[]);
I have a big circle with centre lat/long, the radius of the circle in km and these big circle divided into multiple polygons with data points.
How to get all the bikes that are outside the city boundary (i.e big circle)?
How to get in which polygon how many bikes are existing and how to get in which polygon a given bike location present using polyfill?
How to display all the bike locations, polygons, big circle and filled with hexagons on a map? here I am using MapmyIndia.
How can I implement the above requirements using Uber H3-js and my solution for the point is correct or any better solution is there for the same?