开发者

MySQL storing google maps lat/long data

开发者 https://www.devze.com 2023-03-13 22:21 出处:网络
I have created a map which allows the user to plot multiple markers with the intention on storing them in a database table. The original plan was to store multiple rows per one map like so:

I have created a map which allows the user to plot multiple markers with the intention on storing them in a database table. The original plan was to store multiple rows per one map like so:

------------------------------------
| mapentryid | mapid | Long | Lat  | 
------------------------------------
| 1          | 1     | X.XX | X.XX |
| 2          | 1     | X.XX | X.XX |
| 3          | 1     | X.XX | X.XX |
| 4          | 2     | X.XX | X.XX |
| 5          | 2     | X.XX | X.XX |
| 6          | 2     | X.XX | X.XX |
| 7          | 2     | X.XX | X.XX |
------------------------------------

But I have since found out that you are able to store multilinestring's in MySQL which sounds perfect for what I want (I think?)

I can insert the data correctly using the following SQL query format:

INSERT INTO table (LatLng)
VALUES (
         MultiLineString(
            LineString(Point(x),Point(y)),
            LineString(Point(x),Point(y)),LineString(Point(x),Point(y))
       )

This adds the multilinestring OK, although they actually come up as the following:

MySQL storing google maps lat/long data

The question is, is the above OK? If so, h开发者_如何学Cow can I convert this data back into something I am able to display on Google Maps?


Why not use POINT data?

INSERT INTO geoTable (mapentryid, mapid, coord) VALUES (
    1, 1, GeomFromText('POINT(15 20)')
);

I always use the 'Well-Known Text (WKT) Format' for geospatial enabled queries in MySQL, they are the most compatible with other systems out there.

To query the stored values:

SELECT mapentryid, mapid, X(coord), Y(coord) FROM geoTable;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号