Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate geoNear or near from mongoDB in MySQL

Tags:

mysql

mongodb

In mongoDB there is a command called geoNear that return the distance to geospatial point store in DB. Also when I use find function in mongoDB I can use a near filter that return registers in DB that is in maxDistance range, for example:

db.collection.find( { localizacion:{ $near: { $geometry: { type: "Point", coordinates: [lng, lat]}}, $maxDistance: 1000}}).

That sentence return the registers in DB that are in 1000 meters from [lng, lat].

So, there is any similar in MySQL?

Thanks you.

like image 591
RdlP Avatar asked Oct 14 '25 18:10

RdlP


1 Answers

SELECT * WHERE st_distance_sphere(point_column, POINT(lng, lat)) < 1000

References:

https://dev.mysql.com/doc/refman/en/spatial-convenience-functions.html#function_st-distance-sphere

https://dev.mysql.com/doc/refman/en/gis-mysql-specific-functions.html#function_point

like image 177
Jayen Avatar answered Oct 17 '25 09:10

Jayen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!