简体   繁体   中英

Is there a way to get POINT coordinate from Lat, Lng using MySQL functions?

I need to get mercator coordinates from Lat , Lng in Node.js. I can use some module (for example, node-sphericalmercator ). But it means that the calculation is done on the Node server, not in MySQL:

// Here is pseudo code example
var sphericalmercator = new Sphericalmercator();

res = "SELECT ALL lat, lng FROM table"

var rs = res.map(function(row) {
    return [sphericalmercator.forward([row.lng, row.lat])]
});

// and only then I can do subsequent INSERTs.
INSERT INTO table VALUES POINTFROMTEXT("POINT(rs[0] rs[1])")

But I'd like to covert Lat , Lng into POINT straightly in MySQL, not on Nodejs server. Is there some functions for this?

INSERT INTO table VALUES SomeFuncThatTraslatesToPoint(Lng, Lat)

I admit i'm no expert, but is this something like what you're trying to do?

Moving lat/lon text columns into a 'point' type column

Specifically the section regarding GeomFromText(CONCAT('POINT(', lat, ' ', lng, ')'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM