Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to query model's location with ->where #23

Open
boryn opened this issue Apr 19, 2023 · 0 comments
Open

How to query model's location with ->where #23

boryn opened this issue Apr 19, 2023 · 0 comments

Comments

@boryn
Copy link
Contributor

boryn commented Apr 19, 2023

Hi!

Unfortunately I'm still a little bit confused on how we should query model records for the specific location?

I tried these:

->where('location', DB::raw((new Point(0, 0))->toGeomFromText()))
// or ->where('location', new Point(0, 0))->toGeomFromText()

which produces this query:

where `location` = ST_GeomFromText('POINT(0 0)', 4326)

but gives no results, though there are records with 0, 0 location.

I tried as well:

->where('location', new Point(0, 0))

which gives an error Object of class TarfinLabs\LaravelSpatial\Types\Point could not be converted to string.

I even tried:

->withinDistanceTo('location', new Point(0, 0), 0)

which produces:

where ST_AsText(location) != POINT(0 0) and ST_Distance(ST_SRID(location, 4326), ST_SRID(Point(0, 0), 4326)) <= 0

but unfortunately it gives us SQLSTATE[42000]: Syntax error or access violation: 1582 Incorrect parameter count in the call to native function 'ST_SRID' error. I bet it's the MariaDB specific problem. But after removing second parameter from ST_SRID(), and having

where ST_AsText(location) != POINT(0 0) and ST_Distance(ST_SRID(location), ST_SRID(Point(0, 0))) <= 0 

there is still another error: SQLSTATE[HY000]: General error: 4079 Illegal parameter data type int for operation 'st_distance'.

The only form which works is:

->where('location', DB::raw('POINT(0, 0)'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant