且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法在Google地图中保存多边形

更新时间:2022-12-18 09:50:22

使用 google.maps.geometry .encoding.encodePath(来编码路径。此方法返回一个字符串,非常适合存储到数据库中。重复使用 google.maps.geometry.encoding.decodePath()

解码字符串请注意: geometry-library默认不加载,您必须通过将& libraries = geometry 附加到maps-API-script的src来加载它。

Please note: the geometry-library isn't loaded by default, you must load it by appending &libraries=geometry to the src of the maps-API-script.

解释为什么不能直接存储路径(例如JSON):

当存储包含LatLng的路径时(数组),您将失去LatLng的原型,这是必不可少的,因为它定义了检索属性的方法( lat() lng()

To explain why you can't store the path directly(e.g. as JSON):
when you store the path(array), which contains the LatLng's, you will lose the prototype of the LatLng's, which is essential because it defines the methods for retrieving the properties(lat() and lng() )