>>A quick look  - I can't see a setCenter function call which is
>> necessary to actually get the map going!
> The GDirections call will perform a setCenter on the map if it
> completes successfully and has the map as an argument. Which is why
> the map eventually shows up.

I added a setCenter() cal and it works fine now;


> Once that has been addressed, the next error occurs here:
> dist = directions1.getDistance().meters + directions2.getDistance
> ().meters
> because the onDirectionsLoad handler has been added to both
> directions1 and directions2.  If directions2 returns a result before
> directions1, it will fail.

Interesting problem.
I came up with the following solution :

I write 2 seperate event handlers which each check if the other
distance has been calculated.
If it has; a third function is called to fill the appropriate div with
the appropriate data

here's the code:

                        function onGDirections1Load()
                        {
                                dist1 = this.getDistance().meters;
                                if(typeof(dist2) != 'undefined')
                                {
                                        display_distance(dist1+dist2);
                                }
                        }

                        function onGDirections2Load()
                        {
                                dist2 = this.getDistance().meters;
                                if(typeof(dist1) != 'undefined')
                                {
                                        display_distance(dist1+dist2);
                                }
                        }



                        function display_distance(d)
                        {
                                
document.getElementById("gdirections").innerHTML = "Distance: " +
d/1000 + " km ";

                                if(trip_kind == "dropoff")
                                {
                                        
document.getElementById("gdirections").innerHTML+="(" +
dist1/1000 + " + " + dist2/1000 + ")";
                                }

                                document.getElementById("distance").value = d;
                        }

Any comments or improvements?

Best regards,
Marvelade
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" 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-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to