我有以下字符串形式的谷歌地图路线
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);
}
});
}