【发布时间】:2021-09-09 08:48:01
【问题描述】:
我正在开发一个自行车共享应用程序,我有以下要求。
-
显示一定半径内用户位置附近的所有自行车。
为此,我提出了一种获取自行车所有索引的方法 特定分辨率的位置并从用户位置获取所有索引 使用 kRing 函数的半径,然后找到所有自行车位置 在 kRing 索引中。
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] || [])],
[]);
-
我有一个中心纬度/经度的大圆,圆的半径以公里为单位,这些大圆分成多个带有数据点的多边形。
城市边界外(即大圈)的所有自行车如何获取?
如何使用 polyfill 获取存在多少自行车的多边形以及如何获取给定自行车位置存在的多边形?
-
如何在地图上显示所有自行车位置、多边形、大圆圈和填充六边形?这里我使用的是 MapmyIndia。
如何使用 Uber H3-js 实现上述要求,并且我的解决方案是正确的,或者是否有更好的解决方案?
【问题讨论】:
标签: javascript geolocation maps uber-api h3