Google地图保存多边形并使用PHP指向MySQL [英] Google Maps Save Polygon and points in MySQL using PHP
问题描述
现在我有一个应用程序,允许用户在Google地图上绘制多边形。我需要使用PHP和MySQL保存这个多边形,但我不确定最佳实践。
我应该启用空间扩展并保存几何吗?我应该将每个垂直(纬度/经度对)保存在一个数组中吗?我不知道的另一种方法?
我想知道最佳做法是什么。使用MySQL空间扩展看起来令人望而生畏。它在WKT中返回事物,然后我必须解析该文本以使其执行其他操作。看起来很复杂。
$ b
这将帮助您确定哪些查询需要您的持久层优化。
如果您要处理很多问题就像查找我在这个空间内的所有对象。您可能想要查看使用空间扩展。然而,如果大多数时候你只是用一个给定的id绘制一个对象,只需将多边形保存为DB中的json blob就可以了。
p>创建表格多边形
(
polygon_id int not null,
vertices_json varchar(4096)
)
Right now I have an application that allows users to draw a polygon on google maps. I need to save this polygon using PHP and MySQL but I'm unsure of best practices.
Should I enable spatial extensions and save the geometry? Should I save each vertical (lat/lng pair) in an array? Another approach I'm unaware of?
I'm wondering what the best practices are. Using MySQL spatial extensions seem daunting. It returns things in WKT and then I have to parse that text to make it do something else. It seems convoluted.
It's best to think of your usage scenarios when planning out your storage layer.
This will help you figure out which queries you'll want your persistence layer to optimize for.
If you're going to handle lot's of queries like, "Find me all objects within this space". You may want to look at using the spatial extensions.
However, if most of the time you're simply drawing an object with a given id, simply saving the polygons as a json blob in the DB may do.
CREATE TABLE Polygons ( polygon_id int not null, vertices_json varchar(4096) )
这篇关于Google地图保存多边形并使用PHP指向MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!