简体   繁体   English

谷歌地图使用PHP保存多边形并在MySQL中指向

[英]Google Maps Save Polygon and points in MySQL using PHP

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. 我需要使用PHP和MySQL保存这个多边形,但我不确定最佳实践。

Should I enable spatial extensions and save the geometry? 我应该启用空间扩展并保存几何图形吗? Should I save each vertical (lat/lng pair) in an array? 我应该将每个垂直(lat / lng对)保存在一个数组中吗? Another approach I'm unaware of? 另一种我不知道的方法?

I'm wondering what the best practices are. 我想知道最佳做法是什么。 Using MySQL spatial extensions seem daunting. 使用MySQL空间扩展似乎令人生畏。 It returns things in WKT and then I have to parse that text to make it do something else. 它返回WKT中的内容然后我必须解析该文本以使其执行其他操作。 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. 但是,如果大多数情况下您只是绘制具有给定id的对象,则只需将多边形保存为DB中的json blob即可。

CREATE TABLE Polygons ( polygon_id int not null, vertices_json varchar(4096) ) CREATE TABLE多边形(polygon_id int not null,vertices_json varchar(4096))

You can also use : google.maps.geometry.encoding to encode/compress paths 您还可以使用: google.maps.geometry.encoding来编码/压缩路径

http://code.google.com/intl/fr/apis/maps/documentation/utilities/polylinealgorithm.html http://code.google.com/intl/fr/apis/maps/documentation/utilities/polylinealgorithm.html

I once used this to save in database thousands of directions and it is quite convenient. 我曾经用它来保存数千个方向的数据库,非常方便。

花点时间熟悉空间扩展,因为它们将帮助您完成任务,而不仅仅是这个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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