Hey everyone, this is my first post!
I am having issues with some Google Maps Javascript code I have
implemented on one of my projects. The code works, however returns a
"Stop Running This Script" IE dialog when there are many destinations
to process. I know that this dialog is showing because I have the IE
options enabled for script debugging. I believe the process being so
slow is problem with my results not being correct too. I get different
desitnations being returned as "closer" when I know that a certain one
is actually only 10 miles away.
Basically what I'm currently doing in code is.
1 - Allow the user to select a Company Branch
2 - Load all of the Destination Branches and their addressses from a
SQL database and populate a hidden gridview on the aspx page.
3 - Insert the selected company branch's address into a Javascript
variable.
4 - Loop through all of the destination branches in the hidden
gridview in javascript and make a Google maps Directions call for each
record in the grid.
5 - Upon returning the route for each call, if the route's miles are
less than the previous route's mileage, then save that branche's ID in
an outside variable (closestBranchCode) and save the mileage in
another outside variable (closestBranchDistance).
Continue Steps 4-5 until each record in the grid has been processed.
The code works when the destinations grid has 5 or so addresses, but
if more then the IE warning is shown and the results are not accurate.
Does anyone else have a revised solution that would work?
Thank you!
Javascript Code Used:
function findNearestBranch() {
directionsDisplay = new google.maps.DirectionsRenderer();
var myOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
var branchAddress;
var gvDrv;
if (document.getElementById('<%=branchAddress.ClientID%>')!=null){
branchAddress = document.getElementById("<%=branchAddress.ClientID
%>").value;}
if (document.getElementById('<%=grdNearestARGS.ClientID%>')!=null)
gvDrv = document.getElementById("<%=grdNearestARGS.ClientID%>");
var closestBranchCode = 0;
var closestBranchDistance = 10000000000000;
var counter = 0;
for (i=1; i<gvDrv.rows.length; i++) {
var cell = gvDrv.rows[i].cells;
var address = cell[3].innerHTML + ' ' + cell[4].innerHTML + ', ' +
cell[5].innerHTML + ' ' + cell[6].innerHTML;
var request = {
origin:branchAddress,
destination:address,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
counter = counter + 1;
if (status == google.maps.DirectionsStatus.OK) {
var currentDistance =
roundNumber((((response.routes[0].legs[0].distance.value) / 1000) *
0.6214), 1);
var cell2 = gvDrv.rows[counter].cells;
var branchCode = cell2[0].innerHTML;
if (counter == 1) {
closestBranchDistance = currentDistance;
closestBranchCode = branchCode; }
else {
if (currentDistance < closestBranchDistance) {
closestBranchDistance = currentDistance;
closestBranchCode = branchCode;
}
}
for (i=0;i<document.getElementById('<%=cboFacility.ClientID
%>').length;i++) {
if (closestBranchCode == document.getElementById('<
%=cboAirgasFacility.ClientID%>').options(i).value) {
document.getElementById('<%=cboAirgasFacility.ClientID
%>').options(i).selected = true;
}
}
}
});
}
}
--
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.