Supongamos que tengo una tabla de 2 columnas como esta:Encuentra la distancia entre dos puntos en MYSQL. (Utilizando el tipo de datos Point)
| user_id | int(11) | NO | UNI | NULL | |
| utm | point | NO | MUL | NULL | |
Como se puede ver, es muy simple. utm es un Punto tipo de datos. Lo inserto de esta manera:
INSERT INTO mytable(user_id, utm) VALUES(1, PointFromWKB(point(50, 50)));
Luego, creo un índice espacial.
ALTER TABLE mytable ...add spatial index on(utm) or something. (forgot)
Muy bien, todo está bien. Ahora, quiero seleccionar * donde distancia < 99999. Pero no funciona!
//This is supposed to select all where the distance is less than 99999999.
set @mypoint = PointFromWKB(point(20,20))
select * from mytable where GLength(LineString(utm, @mypoint)) < 9999999;
Empty set (0.00 sec)
select * from mytable where GLength(LineStringFromWKB(LineString(utm, @mypoint))) < 9999;
Empty set (0.00 sec)
Por cierto, me han tratado de INSERT INTO sin la PointFromWKB ... y no funcionó ... por eso alguien sugirió que PointFromWKB a mí.
Calcula la distancia según coordenadas geográficas o coordenadas planas. –