Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. const s2 = require('@radarlabs/s2');
  2.  
  3. const user1LongLat = [-73.95772933959961, 40.71623280185081];
  4. const user2LongLat = [-73.95927429199219, 40.71629785715124];
  5. const user3LongLat = [-73.99206161499023, 40.688708709249646];
  6.  
  7. const user1S2 = ["user1", new s2.CellId(new s2.LatLng(user1LongLat[1], user1LongLat[0])).parent(13)];
  8. const user2S2 = ["user2", new s2.CellId(new s2.LatLng(user2LongLat[1], user2LongLat[0])).parent(13)];
  9. const user3S2 = ["user3", new s2.CellId(new s2.LatLng(user3LongLat[1], user3LongLat[0])).parent(13)];
  10.  
  11. const groups = {};
  12. [user1S2, user2S2, user3S2].forEach(([userId, cellId]) => {
  13. const group = groups[cellId.token()] || [];
  14. group.push(userId);
  15. groups[cellId.token()] = group;
  16. });
  17.  
  18. console.log(groups); // { '89c2595c': [ 'user1', 'user2' ], '89c25a4c': [ 'user3' ] }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement