【发布时间】:2013-01-31 23:30:50
【问题描述】:
我有一张地图,用户可以在其中绘制折线,对其进行编码,然后将其保存到 mySQL 数据库中。然后,还有另一个地图从数据库中查询编码字符串,解码折线并将其显示在地图上。
我正在使用几何库中的encodePath() 函数,如下所示:
if(overlayType == 'POLYGON'){
newPolygonOverlay = overlaysArray[0]; //only one overlay
newPolygonPath = newPolygonOverlay.getPath(); //get the path
newPolygonPathCoordsStr = google.maps.geometry.encoding.encodePath(newPolygonPath); //encode it
这段代码会产生这样的字符串:
wwzhBz~|gP~mhMygvCt`cDjgiH{ohIf{fA
然后我继续使用 mediumtext 类型将此字符串存储在 mySQL DB 中。
第二张图,查询数据库,得到编码后的折线字符串,和我原来保存的一模一样。
然后我使用几何库中的 decode 函数对字符串进行解码并创建折线,如下所示:
var array = google.maps.geometry.encoding.decodePath(str); //str contains the encoded string from the db
var levels = decodeLevels("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
var Poly = new google.maps.Polyline({
path: array,
levels: levels,
strokeColor: '66FF00',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
我的问题是,在途中的某个地方,一些折线点弄乱了,生成的折线与原来的不一样。
我尝试在 mySQL 中使用 blob 类型。结果一样。
我尝试通过在第二个映射上用编码字符串声明一个字符串变量来绕过数据库。结果一样。
【问题讨论】:
-
line 应该是什么样子?
-
如果您在此处插入线路看起来是否正确? developers.google.com/maps/documentation/utilities/…
-
原始行看起来正确,但从数据库查询的行不正确。我测试了几行,发现“\b”没有存储在数据库中,这是我的问题。解决方案似乎是像“\\b”一样逃避它。还有哪些字符需要转义?
标签: google-maps-api-3 google-polyline