Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps Load Route
    text
    copied!<p>I've got a google map route in the form of the following string</p> <pre><code>NewRoute = '{"start":{"lat":51.5479454,"lng":-0.04057739999996102},"end":{"lat":51.5166787,"lng":-0.0596227999999428},"waypoints":[[51.5474343,-0.07557889999998224]]}'; </code></pre> <p>which I want to load onto a map. How do I convert the string NewRoute into the array os so it can be used in the following function?</p> <pre><code>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&lt;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); } }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload