On 12 April 2011 21:16, Prophet <[email protected]> wrote:
> For this line: markerNodes = markerNodes.sort(fSortOnState);
>
> I keep getting: fSortOnState is not defined
I imagine its a scoping issue. you probably can fix it by moving the
actual function just above the sort command. The function needs to be
visible, before it can call it.
... but I dont think the function will solve your issue, that function
really just implements "ORDER BY distance,state" which is not what you
want.
Personally I would solve it (and have done in the past for similar
requirements) using associative arrays. This pseudo javascript should
hopefully get you close: (assumes the results are already in distance
order! eg from mysql)
var obj = new Object()
for (var i = 0; i < markerNodes.length; i++) {
var state = markerNodes[i].getAttribute("state");
if (!obj[state])
obj[state] = new Array();
obj[state].push(i);
}
for (state in obj) {
for(q=0;q<obj[state].length;q++) {
i = obj[state][q];
var name = markerNodes[i].getAttribute("name");
var address = markerNodes[i].getAttribute("address");
.......
//do all the other stuff with the marker here.
}
}
--
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.