Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't Deserialize GoogleMaps DirectionsResult Object
    text
    copied!<p>I'm using the GoogleMaps API v3.0 and trying to save a DirectionsResult to my database and then retrieve it later to use on a map. My problem is that when I try to re-hydrate the saved object by pulling its JSON representation from my database, the object is just dumb JSON, it doesn't have the original methods and functions of its constituent objects. So, I built a fix routine that takes the dumbalt text JSON and rebuilds it by reconstructing all the LatLng and LatLngBound objects. But, something is still missing because my fixed object doesn't work like the original, the two points show up on my map but the purple line between them is missing.</p> <p>Would appreciate any advice on either a better technique for serialization/hydration or any ideas as to what my fix routine might be missing.</p> <p>Thanks</p> <p><img src="https://i.stack.imgur.com/alUrq.png" alt="alt text"> <img src="https://i.stack.imgur.com/a0IQ6.png" alt="alt text"></p> <pre><code>request = { origin: homeLocation, destination: jobLocation, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { var str = Ext.encode(response); //&lt;&lt;==SAVING RAW JSON OBJECT TO DB (I USE ExtJs) var z = eval('(' + str + ')'); //&lt;&lt;==REHYDRATING DirectionsResult RAW JSON OBJECT FixDirectionResult(z); //&lt;&lt;==ATTEMPT TO RE-ESTABLISH ORIGINAL OBJECTS directionsRenderer.setDirections(z); //&lt;&lt;==THIS WORKS WITH response BUT NOT WITH z } ); function FixDirectionResult(rslt) { for(r=0; r&lt;rslt.routes.length; r++) { var route = rslt.routes[r]; var bounds = route.bounds; route.bounds = new google.maps.LatLngBounds( new google.maps.LatLng(bounds.U.b,bounds.O.d), new google.maps.LatLng(bounds.U.d,bounds.O.b)); for(l=0; l&lt;route.legs.length;l++) { var leg = route.legs[l]; leg.start_location = new google.maps.LatLng(leg.start_location.wa,leg.start_location.ya); leg.end_location = new google.maps.LatLng(leg.end_location.wa,leg.end_location.ya); for(s=0; s&lt;leg.steps.length;s++) { var step = leg.steps[s]; step.start_location = new google.maps.LatLng(step.start_location.wa,step.start_location.ya); step.end_location = new google.maps.LatLng(step.end_location.wa,step.end_location.ya); for(p=0;p&lt;step.path.length;p++) { var path=step.path[p]; step.path[p] = new google.maps.LatLng(step.path.wa,step.path.ya); } } } for(o=0; o&lt;route.overview_path.length;o++) { var overview = route.overview_path[o]; route.overview_path[o] = new google.maps.LatLng(overview.wa,overview.ya); } } } </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