Hi,
I appreciate if someone can help me out on this one as I am not that
familiar with Javascript/Googlemap API.
I am trying to compute network distances between pairs of locations using
google map api using the code below.
The problem is that it only shows the distance result for the last pair
(Point B, Point D).
I believe that onGDirectionsLoad() needs to be corrected to do what I would
like to do.
Eventually, I would like to save the result in .csv or .txt file.
Thank you very much for your help in advance.
Taka
+++++++++++++++ CODE
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
var map = null;
var direction = null;
var rootMapTimer = null;
// The addresses of origins
var originArray = new Array(Point A, Point B);
// The addresses of destinations
var destinArray = new Array(Point C, Point D);
// Initialization
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
direction = new GDirections(map,
document.getElementById("direction"));
GEvent.addListener(direction, "load", onGDirectionsLoad);
//routeMap(new Array(originArray[iCnt], destinArray[iCnt]));// 最初の検索
}
}
// Generate pairs of locations
function calcDist()
{
for (var iCnt = 0; iCnt < originArray.length; iCnt++)
{
// Pairs of locations (POL)
direction.clear();
pol = [originArray[iCnt], destinArray[iCnt]];
routeMap(pol);
}
}
// Route identification
function routeMap(pointArray)
{
var option = {locale: 'ja_JP', travelMode:
G_TRAVEL_MODE_DRIVING};
direction.loadFromWaypoints(pointArray, option);
}
// Distance/Duration calcuation
function onGDirectionsLoad()
{
var distance = direction.getDistance();
var duration = direction.getDuration();
for (iCnt = 0; iCnt < originArray.length; iCnt++)
{
document.getElementById("result").innerHTML +=
originArray[iCnt] + " → " + destinArray[iCnt] + " Distance:
" + distance.html + " Time elapsed: " + duration.html + "<br/>";
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Maps API V2" 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.