文字列化された方向レンダラー json の配列があります。
array[1].direction = '{\"routes\":[{\"bounds\":\"\....'
array[1].direction = '{\"routes\":[{\"bounds\":\"\....'
.
.
これは、マップ上にこれらの json をレンダリングするために行ったことです。
for (var x=2; x<array.length; x++) {
renderDirections(array[x].direction);
}
function renderDirections(result){
var directionRenderer = new google.maps.DirectionsRenderer();
myDirections = JSON.parse(result, function(name, value){
if(/^LatLngPlaceHolder\(/.test(value)) {
var match = /LatLngPlaceHolder\(([^,]+),([^,]+)\)/.exec(value);
return new google.maps.LatLng(match[1], match[2]);
}
else{
return value;
}
});
directionRenderer.setMap(map);
directionRenderer.setDirections(myDirections);
directionRenderer.setOptions({suppressMarkers:true,preserveViewport:true});
}
これを行う"Uncaught SyntaxError: Unexpected token \"
と、JSON.parse 行でエラーが発生します。
ただし、もしそうなら:
for (var x=2; x<array.length; x++) {
var examplejson = '{\"routes\":[{\"bounds\":\"\....'; //note that its an example json which i logged from `array[x].direction`
renderDirections(examplejson);
}
json をレンダリングします。