Ticket #1248 (closed defect: fixed)
Geographical plugin is inaccurate
| Reported by: | ccunningham | Owned by: | jwage |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | Geographical | Version: | 1.0.0 |
| Severity: | Keywords: | ||
| Cc: | Has Test: | no | |
| Status: | Pending Core Response | Has Patch: | no |
Description
The geographical plugin rounds the latitude down to one decimal place in the first part of the query, which produces very inaccurate results. I noticed it does this since without doing so, doctrine tries to make that latitude a table reference and throws an exception. Unfortunately the tradeoff here is that the calculation is now way off. For example, I did two local zip codes and doing the raw query in MySQL with the full latitude, it reports the accurate distance of around 8 miles. Using the way doctrine does it, it reports the distance as over 100 miles.
Example, doctrine way:
SELECT t.id AS t__id, t.type AS t__type, t.email AS t__email, t.corporate_name AS t__corporate_name, t.zip AS t__zip, CONCAT(t.last_name, ',', ' ', t.first_name) AS t__0, CONCAT(t.city, ' ', t.state, ' ', t.zip) AS t__1, ((ACOS(SIN(39.9 * PI() / 180) * SIN(t2.latitude * PI() / 180) + COS(39.939871 * PI() / 180) * COS(t2.latitude * PI() / 180) * COS((-83.166702 - t2.longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS t2__2 FROM T2_Entity t LEFT JOIN T2_Zip t2 ON t.zip = t2.zip WHERE (t.type = 'physician' AND t.profile_id = 1);
returns 104.06 miles
WIth full latitude:
SELECT t.id AS t__id, t.type AS t__type, t.email AS t__email, t.corporate_name AS t__corporate_name, t.zip AS t__zip, t2.zip AS t2__zip, t2.latitude AS t2__latitude, t2.longitude AS t2__longitude, CONCAT(t.last_name, ',', ' ', t.first_name) AS t__0, CONCAT(t.city, ' ', t.state, ' ', t.zip) AS t__1, ((ACOS(SIN(39.939871 * PI() / 180) * SIN(t2.latitude * PI() / 180) + COS(39.939871 * PI() / 180) * COS(t2.latitude * PI() / 180) * COS((-83.166702 - t2.longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) miles FROM T2_Entity t LEFT JOIN T2_Zip t2 ON t.zip = t2.zip WHERE (t.type = 'physician' AND t.profile_id = 1);
returns 8.86 miles