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
302 views Asked by sebsebli At
2
There are 2 answers
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
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in NODE.JS
- Using Puppeteer to scrape a public API only when the data changes
- How to request administrator rights?
- How do I link two models in mongoose?
- Variable inside a Variable, not updating
- Unable to Post Form Data to MongoDB because of picturepath
- Connection terminated unexpectedly while performing multi row insert using pg-promise
- Processing multiple forms in nodejs and postgresql
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- How to change the Font Weight of a SelectValue component in React when a SelectItem is selected?
- My unban and ban commands arent showing when i put the slash
- how to make read only file/directory in Mac writable
- How can I outsource worker processes within a for loop?
- Get remote MKV file metadata using nodejs
- Adding google-profanity-words to web page
- Products aren't displayed after fetching data from mysql db (node.js & express)
Related Questions in GEOLOCATION
- Ionic/Capacitor: Background Location Tracking on iOS and Android?
- Getting updated latitude longitude in background without internet on android
- How to properly trigger geofence?
- Wordpress Website to store Geolocation of the users and search based on it
- Generate country names from IP Addresses in R and saving these as a new variable in a dataframe
- C# Blazor WebAssembly - how to access device heading
- Vaadin 24 stop Geolocation maplibre
- Android App Rejected for Background Location Access Using Capacitor Geolocation
- Slow Location Tracking [Flutter]
- What is wrong with this code? Request for permissions not appearing Android Studio
- Apple Wallet Event Pass Appears on Lockscreen Outside MaxDistance Range
- I want to search for address from google maps API and fill it automatically in Text Form Field
- iOS app with location only works on iPhone and not on iPad, why?
- MAUI MAP - How to get the business type and name from Location?
- Is there a way to set a cookie using JS and force a dynamic element reliant on the cookie to update without reloading the page?
Related Questions in MATCHING
- why result of regular expression match in not as expected?
- Importing large contact file error message and failure --why?
- Custom pattern matching between two columns and replacing to keep within-column groups consistent
- Unable to find a match for a substring in column of my dataframe
- numerical/user defined similarity calculation in reclin2
- Combining matchit objects for descriptive analysis (CRAN/R)
- Adding together matrices of two different dimensions with column/row matching
- Copy and paste specific data from an Excel sheet to a web page based on a specific condition, repeating this process more than 1000 times
- R Coarsened Exact Matching, list with matched controls
- record matching/similarity calculation for numbers and characters
- Searchbox on Sheet1 for finding a specific row on a table placed in Sheet2
- I want to highlight cells that are not represented in table
- PowerShell move all files containg exact string in their body
- Matching up values in two separate columns using VBA
- Replacing rows of NA with another row meeting specific column matching
Related Questions in GEOHASHING
- Get longitude and latitude for the corners of a geohash
- Are geohash tiles the same size anywhere on the globe?
- Error loading data - google sheet app script, javascript, geohash
- Scalability of GeoHash Based proximity services
- firebase order by not working as expected
- How to find if the point is within a bounding box in Tile38?
- Delete geographic point in dynamodb
- Elasticsearch how to use geohex_grid or geohash_grid return a full detail (or at lease get full detail when doc_count:1)
- GeoHashUtils Library not working as expected
- Find N closest points with geohash
- Location based GeoFire queries . How to load the documents in batches
- Visualize Geohash after Drawing it on same map (Streamlit Folium)
- Is there a table for every country's geohash codes?
- Geospatial rolling average from geohashes on BigQuery
- Tinder-like search based on distance in Flutter - Most efficient way?
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?
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)
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.)