Using POINT DataType to store Lat,Lng from GPS (MySQL 5.7)

CREATE TABLE Positions ( id_location int PRIMARY KEY AUTO_INCREMENT, position POINT NOT NULL ); INSERT INTO Positions(position) VALUES(POINT(-6.175489, 106.827208)); INSERT INTO Positions(position) VALUES(POINT(-6.173105, 106.808584)); SELECT X(position) AS lat, Y(position) AS lng FROM Positions; /* Output ------------------------ lat lng ------------------------ -6.175489 106.827208 -6.173105 106.808584 */ SELECT * FROM Positions; /* Output -------------------------------------------------- id_location position -------------------------------------------------- 1 {"x":-6.175489,"y":106.827208} 2 {"x":-6.173105,"y":106.808584} */
MySQL 5.7

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.