将Google地图多边形保存到PostgreSQL数据库 [英] save google map polygon to postgreSQL database

查看:672
本文介绍了将Google地图多边形保存到PostgreSQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个基于网络的应用程序,用户将在地图上创建一个多边形,并且数据库
将返回感兴趣的点。



PostgreSQL以与Google地图多边形不同的方式保存多边形。



那么如何将用户多边形保存为postgis?



我已经使用google maps v3 api和geojson

解决方案

有些代码会很有用。在没有这个的情况下,这是一个最好的猜测通用答案:总的来说,你需要弄清楚如何将每种格式映射(转换)为另一种格式。然后,您可以在保存数据库之前将其转换为适合数据库的格式,并在检索时将其从数据库格式转换为Google地图格式。我想每个多边形都是两种格式的经纬度对,所以它不应该太难。



或者,由于您使用的是JSON,因此您可以只需将JSON保存到数据库中的文本字段(或即将发布的PostgreSQL 9.2版本中的JSON字段)即可:

http://www.postgresql.org/docs/9.2/static/datatype-json.html



然而,如果您想在数据库中执行显然会限制您的选项的地理查询。


I develop a web-based application where a user will create a polygon on a map and the database will return points of interest.

The problem is that the postgreSQL saves the polygon in a different way than google map polygon.

So how I can save the user polygon to postgis?

I already use google maps v3 api and geojson

解决方案

Some code would be useful. In the absence of that here's a best guess generic answer: In general terms you will need to work out how to map (convert) each format to the other. Then you can convert to the format suitable for the database before you save and convert from database format to google maps format when you retrieve. I imagine each polygon is a set of latitude/longitude pairs in both formats so it shouldn't be too difficult.

Alternatively, since you're using JSON, you could just save the JSON to a text field in the database (or to a JSON field in the upcoming 9.2 release of PostgreSQL):

http://www.postgresql.org/docs/9.2/static/datatype-json.html

However if you would like to perform geographical queries in the database that would obviously limit your options.

这篇关于将Google地图多边形保存到PostgreSQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆