On Jun 4, 4:51 pm, zeddy <[email protected]> wrote:
> I was just looking at this
> example:http://gmaps-samples.googlecode.com/svn/trunk/googlebar/googlebar_dir...
>
> It has an interesting approach to retrieving directions for a central
> point and an array of markers. You can look at the source, but briefly
> it does this:
>
> function getDirections(markers, tbody, num)
> {
> ...
> var dir = new GDirections();
>
> GEvent.addListener(dir, "load", function() {
> ...
> if ((num+1) < markers.length) getDirections(markers, tbody, (num
> +1));
> });
>
> dir.load("from: ....);
>
> }
>
> It is called initially with the markers array and i=0 for the first
> point. It creates a new GDirections for marker 'i' and when the load
> event calls the function to calculate the distance, that function also
> calls getDirections() again with i+1 for the next marker to be
> processed. The key point is that it enforces serial processing of each
> marker in the array, because the load event processes marker "i" and
> then initiates processing of marker "i+1". On the other hand, it
> creates a GDirection for every marker to be processed.
>
> I think I can use this to process a series of GDirection queries in
> sequence. Just put them in an array and when the 'load' listener
> finishes with query "i", it initiates the query for "i+1".
>
> I have some questions:
> 1. if there are N markers to be processed, this will create a
> GDirections object for each one. Isn't that a lot of overhead? What if
> there's 50 markers? How many GDirections is too many? Does it depend
> on how big the result of the 'load' is (e.g. the result is inside the
> GDirection object).
I believe local search will return at most 8 results which limits the
size of the problem.
Beware of the GDirections quota and speed limits (per Mike Williams'
message earlier in this thread).
-- Larry
>
> 2. Generally, recursive solutions are usually easy/efficient to code,
> but they use more resources. If there are N markers, this will end up
> as N nested calls on the stack. Maybe not a problem for 5 points, but
> what about 50 points? How deep is too deep?
>
> 3. In the code, each GDirection has a listener function for the 'load'
> event. In this case, it's an anonymous function. Does it use fewer
> resources to use a named function instead? If the function is
> anonymous, does the GDirection object get a copy of the function, but
> only a pointer if a named function is used?
>
> 4. I usually code my listener functions with "this", e.g.:
> function onload()
> {
> var p=this.getPolyline();
> mymap.addOverlay(p);
>
> }
>
> Does use of "this" depend on whether an anonymous or named function is
> used? Same thing?
>
> Thanks.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---