malhal / Laravel-Geographical

Easily add longitude and latitude columns to your records and use inherited functionality for calculating distances
MIT License
283 stars 49 forks source link

geofence with pgsql error #21

Closed satwaihlaing closed 4 years ago

satwaihlaing commented 5 years ago

i install and use it as instructed. I can get the distance method working but when i use geofence it give me error

SQLSTATE[42703]: Undefined column: 7 ERROR: column "distance" does not exist LINE 1: ...PI()) * 60 * $4) as distance from "stores" having distance B... ^ (SQL: select "stores".*, ((ACOS(SIN(16.8095486 * PI() / 180) * SIN(stores.latitude * PI() / 180) + COS(16.8095486 * PI() / 180) * COS(stores.latitude * PI() / 180) * COS((96.1209137 - stores.longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) as distance from "stores" having distance BETWEEN 1 AND 1)

axkuechler commented 4 years ago

The problem occurs due to the inability of Postgres to have subquery aliases in HAVING clauses. This is possible in MySQL only.

I created a similar package with both, MySQL and Postgres support and a faster, more efficient calculation method when working with a large set of locations here.