我有一张地图,用户可以绘制一条折线,对其进行编码,然后将其保存到mySQL数据库中。然后,还有另一个映射,它从DB查询编码的字符串,解码polyline并在地图上显示它。
我正在使用几何库中的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然后继续使用中介文本类型将此字符串存储在mySQL DB中。
第二个映射查询DB以获得编码的polyline字符串,它与我最初保存的字符串完全相同。
然后,我使用几何库中的decode函数解码字符串,并创建polyline,如下所示:
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类型。同样的结果。
我试图绕过DB,在第二个映射中声明一个字符串变量,并使用编码的字符串。同样的结果。
发布于 2015-01-29 12:57:39
(由OP在问题编辑中回答。转换成社区wiki的答案。见Question with no answers, but issue solved in the comments (or extended in chat) )
“任择议定书”写道:
问题是由javascript解释(并删除)反斜杠字符。因此,当编码的字符串到达DB时,它不再包含反斜杠,从而使polyline成为一个完全不同的polyline。我尝试用双反斜杠替换单个反斜杠:"\“-> "\",但在对encode函数执行替换之前,我一直遇到问题;如下所示:
newRoutePathCoordsStr = google.maps.geometry.encoding.encodePath(newRoutePath).replace(/\\/g,"\\\\");https://stackoverflow.com/questions/14637088
复制相似问题