Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const s2 = require('@radarlabs/s2');
- const user1LongLat = [-73.95772933959961, 40.71623280185081];
- const user2LongLat = [-73.95927429199219, 40.71629785715124];
- const user3LongLat = [-73.99206161499023, 40.688708709249646];
- const user1S2 = ["user1", new s2.CellId(new s2.LatLng(user1LongLat[1], user1LongLat[0])).parent(13)];
- const user2S2 = ["user2", new s2.CellId(new s2.LatLng(user2LongLat[1], user2LongLat[0])).parent(13)];
- const user3S2 = ["user3", new s2.CellId(new s2.LatLng(user3LongLat[1], user3LongLat[0])).parent(13)];
- const groups = {};
- [user1S2, user2S2, user3S2].forEach(([userId, cellId]) => {
- const group = groups[cellId.token()] || [];
- group.push(userId);
- groups[cellId.token()] = group;
- });
- console.log(groups); // { '89c2595c': [ 'user1', 'user2' ], '89c25a4c': [ 'user3' ] }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement