On Jan 11, 4:09 am, dipens <[email protected]> wrote: > Hi, > > In my application - I am displaying a route (with all alternative > routes) on a map > and allowing the user to toggle between other routes. They toggle by > clicking on (in my example) Route 1 or Route 2. > If they click on route 1, I just want route 1 to be displayed > (alongside the original route). > If they then click on route 2, I only want route 2 to be displayed > (alongside the original route). > > The problem I am facing is that I am unable to remove the route I > don't want displayed. > I don't think my solution is very good as I am trying to: > 1) Clear the map > 2) Call google directions to request the original route again (which I > think is unnecessary) > 3) Display the required route (I am calling google directions every > time the use toggles between routes - even if a route has already been > displayed in the current 'session'). > > This means that everytime the user toggles, I am calling the > directions service twice. > > What I am trying to achieve is: > 1) Remove the route that isn't required. > 2) Call google directions and draw the new route (and save to a > cache). > This means that the next time the user toggles to this route, I don't > need to call the google directions service and just read the data from > the cache. > > For an example, please see this: > > http://www.differentum.com/map-test.html
You need to keep a reference to the directions objects so you can use them again (to change the route being displayed)... Return a reference to the directionsRenderer created in your "renderDirections" function, then us that to hide the route (setMap(null)) or change its properties (not sure that is possible, but if you get the polyline, you can call setOptions on it). > > Has anyone got any examples of where this is done? Don't know of any myself, other than those that have been posted to the group. -- Larry > > Thanks > Dipen -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
