我有一张地图,用户可以在其中绘制折线,对其进行编码,然后将其保存到mySQL数据库。然后,还有另一个地图从数据库查询编码字符串,解码折线并将其显示在地图上。谷歌地图v3错误绘图编码折线
我使用的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使用中文文本类型。
第二张地图查询数据库以获得编码的折线字符串,这与我最初保存的一样。
我然后使用从几何库中的解码功能解码串并创建折线,像这样:
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类型。同样的结果。
我试图通过在编码字符串的第二个映射上声明一个字符串变量绕过数据库。同样的结果。
什么是[线](http://www.geocodezip.com/v3_GenericMapBrowser.asp?filename=SO_Polyline_encoded.xml)应该是什么样子的? – geocodezip
如果你插入这里,线条看起来是否正确? https://developers.google.com/maps/documentation/utilities/polylineutility – Rick
原始行看起来正确,但从数据库查询的行不。我测试了几行,发现“\ b”没有存储在数据库中,这是我的问题。解决方案似乎是像“\\ b”一样逃避它。还有哪些角色需要转义? – ehenkle