次の文字列の形式でGoogleマップのルートを取得しました
NewRoute = '{"start":{"lat":51.5479454,"lng":-0.04057739999996102},"end":{"lat":51.5166787,"lng":-0.0596227999999428},"waypoints":[[51.5474343,-0.07557889999998224]]}';
マップにロードしたい。次の関数で使用できるように、文字列 NewRoute を配列 os に変換するにはどうすればよいですか?
function showRoute(oViewMapButton)
{
ButtonName = oViewMapButton.name;
if(ButtonName.length == 13){
var RouteName = "strWayPoints_r" + ButtonName.slice(-1);
var DistanceName = "strDistance_r" + ButtonName.slice(-1);
}else{
var RouteName = "strWayPoints_r" + ButtonName.slice(-2);
var DistanceName = "strDistance_r" + ButtonName.slice(-2);
}
oRoute = document.getElementById(RouteName);
var NewRoute = oRoute.value;
var os = [];
os = NewRoute;
var wp = [];
for(var i=0;i<os.waypoints.length;i++)
wp[i] = {'location': new google.maps.LatLng(os.waypoints[i][0], os.waypoints[i][1]),'stopover':false }
$( "#hid_FieldName3" ).val(DistanceName);
$( "#map-form" ).dialog( "open" );
var request = {
origin:new google.maps.LatLng(os.start.lat,os.start.lng),
destination:new google.maps.LatLng(os.end.lat,os.end.lng),
waypoints: wp,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
alert("There was an unknown error in your request. Requeststatus: \n\n"+status);
}
});
}