following problem: I've got an Array with thousands of entries (people with id and geolocation (lat,long)). The aim is to connect each person with another person within a given radius (e.g. 20km). I'm looking for an efficient way to do so. I've already tried Geohashes but since every entry of the array needs to be compared with every other entry, the execution time is horrible when scaling. I would appreciate any great hint! Thanks a lot. I'm using a NodeJS server for the matching algorithm.
Looking for an JavaScript algorithm to match 2 persons within a given radius
300 Views Asked by sebsebli At
2
There are 2 best solutions below
0
Anatoly
On
I can think of several improvements here:
- If you calculate a distance from Ai point to Aj point then you already have a distance from Aj to Ai. It means you have
N*(N-1)/2comparisons instead ofN*(N-1). - Because you have a constant radius You can take
radius * radius(i.eradius^2) and not to use a square root to compare a calculated distance with a given radius - If all calculations are synchronous you should use something like
worker threadsbecause Node.Js is single-threaded by design.
Maybe you can take a glance at JSTS package because it may save you some time with geospatial calculations.
Another approach is to load all data into DB with a geospatial support, add needed geospatial indexes and use specialized geospatial functions of this DB to calculate a distance and group people by it
Related Questions in JAVASCRIPT
- Angular Show All When No Filter Is Supplied
- Why does a function show up as not defined
- I count the time the user takes to solve my quiz using Javascript but I want the same time displayed on another page
- Set "More" "Less" font size
- Using pagination on a table in AngularJS
- How to sort these using Javascript or Jquery Most effectively
- how to fill out the table with next values in array with one button
- State with different subviews
- Ajax jQuery firing multiple time display event for the same result
- Getting and passing MVC Model data to AngularJS controller
- Disable variable in eval
- javascript nested loops waiting for user input
- .hover() seems to overwrite .click()
- How to sort a multi-dimensional array by the second array in descending order?
- How do I find the fonts that are not loading in a CORS situation ( MoovWeb )?
Related Questions in NODE.JS
- How to solve CERT_UNTRUSTED error in nodemailer
- Run a loop over a callback, node js
- Implementing prerender.io middleware in sails.js
- Token based authorization in nodejs/ExpressJs and Angular(Single Page Application)
- formatting path string in javascript
- One to One screensharing using WEBRTC
- Create polygon from grid (for collisions)
- Strange npm behavior when installing packages like grunt
- Convert JSON.gz to JSON in node js
- "Your npm version is outdated." but it's not. While install yo
- Why put methods on the prototype of a class instead of declaring them in the constructor?
- Node JS Async Response
- mongoose get property from nested schema after `group`
- Cannot Receive Incoming call on Twilio android Client
- How can I change a specific line in a file with node js?
Related Questions in GEOLOCATION
- how capturing geolocation with device offline - cordova
- Polygon shape margin in Java
- GeoLocation fetching wrong latitude longitude
- Using geo-coordinates as vertex coordinates in the igraph r-package
- Tweepy location on Twitter API filter always throws 406 error
- Get Current Location If Checkbox Checked
- How to use AngularJs to load user location, which can be used in the entire application?
- Android studio location
- HTML5 navigator.geolocation.getCurrentPosition always returns undefined
- How to get alert for turning on location services?
- How to Switch ON and OFF GPS
- How to calculate time between 2 geopoints given a route
- How do I enter an "empty" POINT() geometry value into a MySQL field of type POINT?
- Can a geofence contain many other geofences
- MaxMind GeoIP City Returning Incorrect Lat Longs
Related Questions in MATCHING
- subtract column1 (dataframe1) from column2 (dataframe2) based on matching column in both R
- How to get pixel coordinates from Feature Matching in OpenCV Python
- Visiting a supermarket with a shopping list, get all items in the fastest way?
- Java populate array randomly in matching game
- Latent Fingerprint Matching
- Inconsistent match function, if I run twice works (R)
- Search last 4digits and match the exact or nearest result in the database using php
- Javascript Regex partial matching
- Finding matching objects in Java
- Matching two vector paths
- consistent matched pairs in R
- File Handling and making directories to match in bash
- Features matching on multiple images
- Semi-Eulerization Algorithm (for dummies)
- What is the Weight Matrix generated in the Matching package?
Related Questions in GEOHASHING
- Using Kibana4 Tile Map with Geo-Points
- Solr faceting returning the average and the count
- Kibana 3 GeoJSON vs Kibana4 Geohash
- Cassandra CQL 3 - Prefix Select
- Standardizing GPX traces
- MongoDB $centerSphere vs Redis geospatial
- Solr - Using facets to sum documents based on variable precision geohashes
- Why Bounding Box Search executes too long?
- Elasticsearch how to use geohex_grid or geohash_grid return a full detail (or at lease get full detail when doc_count:1)
- Delete geographic point in dynamodb
- How to find if the point is within a bounding box in Tile38?
- Scalability of GeoHash Based proximity services
- firebase order by not working as expected
- Spatial data with mongodb or cassandra
- Looking for an JavaScript algorithm to match 2 persons within a given radius
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
I don't understand why you need to compare the geohash of every entry with every other entry?
Start with an empty Map where each key is a geohash and each value is a Set of ids. For each entry, compute the geohash and add the entry id to the related Set. Now for each entry you can pick any other id from the set, if there is no other you'll need to decrease the precision. (Implementation will be bit different if an entry cannot be matched with multiple others.)