vendredi 24 juin 2016

Find the distance between greater than 100K locations

I have two MySQL tables with locations, table1 and table2 (see below). There are > 100K rows in each table. I'd like to find the distance between every location in these two tables using their geolocations. Here is the MySQL query to find the distance between a single geolocation, e.g, (-37.22, 88.88) and all the locations in table1. $lat = -37.22; $long = 88.88; SELECT id, latitude, longitude, name ((2 * 3960 * ATAN2( SQRT( POWER(SIN((RADIANS($lat - latitude))/2), 2) + COS(RADIANS(latitude)) * COS(RADIANS($long)) * POWER(SIN((RADIANS($long - longitude))/2), 2) ), SQRT(1-( POWER(SIN((RADIANS($lat - latitude))/2), 2) + COS(RADIANS(latitude)) * COS(RADIANS($long)) * POWER(SIN((RADIANS($long - longitude))/2), 2) )) ) )) AS distance FROM table1 ORDER BY distance; Table1 id name latitude longitude 1 foo1 -37.12 62.34 2 foo2 -47.12 72.34 3 foo3 -57.12 82.34 Table2 id name latitude longitude 1 bar1 -38.22 66.11 2 bar2 -48.22 76.11 3 bar3 -58.22 86.11 Given that this is also a big data, I'm not sure where to start. Thoughts?

Aucun commentaire:

Enregistrer un commentaire