hmmm... The issues you specified then could pose a problem for me. I
have more than 500 addresses where I'm reading from an xml file which
you can see I'm traversing using a for loop. So quota may be my
problem. I thought I could call a gdir.load("from: " + fromAddress + "
to: " +
toAddress, { "locale": locale }); in the middle of my for loop with a
listener that would call a function to calculate the distances using
the operator "+=" to keep track of the reoccurring total.


for example this is what I was thinking:

gdir2 = new GDirections();
GEvent.addListener(gdir2, "load",onTotal);

 GDownloadUrl("xmldata.xml", function(data) {
                                var xml = GXml.parse(data);
                                var markers
=xml.documentElement.getElementsByTagName("marker");
                                for (var i = 0; i < markers.length; i+
+) {
                                        var latlng = new GLatLng
(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers
[i].getAttribute("lng")));
                                        var address = markers
[i].getAttribute("address");
                                        var icontype = parseInt(markers
[i].getAttribute("icontype"));
                                        var customMsg = "<br>"
+address;
                                        ************* gdir2.load
("from: " + start + " to: " + address, { "locale": locale });
***********
                                        var marker = createMarker
(latlng, customMsg, icontype, start, address);
                                        map.addOverlay(marker);
                                }
                        });



function onTotal(){
                var distance = gdir2.getDistance();
                var trip = new Array();
                trip = distance.split("mi");
                totaldistance += parseFloat(trip[0]);
                document.getElementById("total").innerHTML =
totalDistance;
}









On Apr 15, 10:59 am, "[email protected]" <[email protected]>
wrote:
> On Apr 15, 8:50 am, loulou2u <[email protected]> wrote:
>
> > I have written a map with several markers (over 100) and if you click
> > on the marker the driving distance and the total round trip miles is
> > written to a <div>. However, is it possible to also gather all the
> > distances in my for loop and get a grand total of distances for all
> > the markers so that I can place it in another <div> that holds the
> > grand total of all points?
>
> Yes.  That is just software.  How do you intend to select the order
> that you visit the points?
>
> If you post a link to your map, I might look at how you are trying to
> do it.
>
> There are a couple of issues you will need to look out for:
> 1. the GDirections call is asynchronous.
> 2. a single GDirections call only supports up to 25 waypoints.
> 3. the is a quota and speed limit applied to GDirections calls.
>
>   -- Larry
>
>
>
> > Thanks.
>
> > Here is some of my code that I wrote using various examples on the
> > web:
>
> >         function initialize() {
> >                 if (GBrowserIsCompatible()) {
> >                         var map = new GMap2(document.getElementById
> > ("map_canvas"));
> >                          map.setCenter(new GLatLng(my coordinates are
> > here), 13);
> >                          gdir = new GDirections();
> >                         GEvent.addListener(gdir, "load",
> > onGDirectionsLoad);
> >                         map.addControl(new GSmallMapControl());
> >                         map.addControl(new GMapTypeControl());
>
> >                         GDownloadUrl("xmldata.xml", function(data) {
> >                                 var xml = GXml.parse(data);
> >                                 var markers =
> > xml.documentElement.getElementsByTagName("marker");
> >                                 for (var i = 0; i < markers.length; i+
> > +) {
> >                                         var latlng = new GLatLng
> > (parseFloat(markers[i].getAttribute("lat")), parseFloat(markers
> > [i].getAttribute("lng")));
> >                                         var address = markers
> > [i].getAttribute("address");
> >                                         var icontype = parseInt(markers
> > [i].getAttribute("icontype"));
> >                                         var customMsg = "<br>" +
> > address;
> >                                         var marker = createMarker
> > (latlng, customMsg, icontype, start, address);
> >                                         map.addOverlay(marker);
>
> >                                 }
> >                         });
>
> >                 }
> >         }
>
> >      function createMarker(point,html,icontype, start, address) {
> >                 var marker = new GMarker(point,icons[icontype]);
> >                 GEvent.addListener(marker, "click", function() {
> >                         setDirections(start, address);
> >                         marker.openInfoWindowHtml(html);
> >                 });
> >                 return marker;
> >          }
>
> >         function setDirections(fromAddress, toAddress) {
> >                 var locale = "en_US";
> >                 gdir.load("from: " + fromAddress + " to: " +
> > toAddress, { "locale": locale });
> >         }
>
> >         function onGDirectionsLoad(){
> >                 var distance = gdir.getDistance().html;
> >                 var trip = new Array();
> >                 trip = distance.split("mi");
> >                 var roundTrip = parseFloat(trip[0]) * 2;
> >                 document.getElementById("distance").innerHTML =
> > "<h2>Driving Distance</h2><b>One-Way: </b>" + distance +
> > "<br><br><b>Round Trip: </b>" + roundTrip + " mi";
> >         }
--~--~---------~--~----~------------~-------~--~----~
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