Skip to content Skip to sidebar Skip to footer

Mysql Wordpress Query Returning A Distance Of Zero For Some Records

I wrote a query against a WordPress Database that selects the 10 closest restaurants, ordered by distance. For some reason, the first three have a distance of zero and I can't for

Solution 1:

The first row is as you have discovered is correctly zero because the two points are identical.

The second row produces 0 distance but it should be about 2 cm. The error is caused by the formula that you are using; it can cause problems with small distances. Google "spherical law of cosines".

The third row's point is identical to that of the second row. Looks like you need to investigate (1) short term fix: eliminate zeroes and almost-zeroes e.g. HAVING distance <= 50 and distance > 0.001 (2) longer term fix: investigate why you've got data points that are duplicates or close enough to be duplicates. Validate your data ... e.g. before you add a new restaurant to the database, check using your distance formula to see if it's already there.

Post a Comment for "Mysql Wordpress Query Returning A Distance Of Zero For Some Records"