Hi,

The code below gives me the difference.   When I use GetDistance I
always get the same distance (in travel mode or driving mode).  The
direction panel gives always the correct distance.

<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
        <meta name="robots" content="noindex,follow" />
        <title>Calculate driving distance with Google Maps API</title>
        <script src="http://maps.google.com/maps?
file=api&v=2&key=ABQIAAAASjQqMOXYcfa7Kl9O0rkVFRQfHI_Yo2Awf0uVYXPjyvKn_9RavBSsrfI9M1X-
C-0aAuNqTnDG45gIQA" type="text/javascript"></script>
        <!-- According to the Google Maps API Terms of Service you are
required display a Google map when using the Google Maps API. see:
http://code.google.com/apis/maps/terms.html -->
        <script type="text/javascript">

    function silentErrorHandler() {return true;}
    window.onerror=silentErrorHandler;

    var url = window.location.toString();
        var geocoder, location1, location2, gDir, startadres, eindadres,
showmap, route;
    var map;
    var directionsPanel;
    var directions;

    //get the parameters from url
    url.match(/\?(.+)$/);
    var params = RegExp.$1;
    // split up the query string and store in an
    // associative array
    var params = params.split("&");
    var queryStringList = {};

    for(var i=0;i<params.length;i++)
    {
           var tmp = params[i].split("=");
        queryStringList[tmp[0]] = unescape(tmp[1]);
    }

    // print all querystring in key value pairs
    startadres = queryStringList["address1"];
    eindadres = queryStringList["address2"];
    showmap = queryStringList["map"];
    route = queryStringList["desc"];

        function initialize() {
                geocoder = new GClientGeocoder();
                gDir = new GDirections();
                GEvent.addListener(gDir, "load", function() {
                        var drivingDistanceMiles = gDir.getDistance().meters / 
1609.344;
                        var drivingDistanceKilometers = 
gDir.getDistance().meters / 1000;
                        // var route = gDir.getRoute(0);
                        document.getElementById("latitude1").value = 
location1.lat;
                        document.getElementById("longitude1").value = 
location1.lon;
                        document.getElementById("latitude2").value = 
location2.lat;
                        document.getElementById("longitude2").value = 
location2.lon;
                document.forms[0].afstand.value = drivingDistanceKilometers;
                        // document.getElementById("longitude2").value = 
route.getDistance
().meters / 1000;
                // alert (document.getElementById("route").innerHTML);

                });
                document.getElementById("address1").value = startadres;
                document.getElementById("address2").value = eindadres;
                showLocation();
        }

        function showLocation() {


            geocoder.getLocations(document.forms[0].address1.value, function
(response) {
                        if (!response || response.Status.code != 200)
                        {
                                alert("Sorry, " + startadres + " is niet 
gevonden.");
                        }
                        else
                        {
                                location1 = {lat: 
response.Placemark[0].Point.coordinates[1], lon:
response.Placemark[0].Point.coordinates[0], address: response.Placemark
[0].address};
                                
geocoder.getLocations(document.forms[0].address2.value, function
(response) {
                                        if (!response || response.Status.code 
!= 200)
                                        {
                                                alert("Sorry, " + eindadres + " 
is niet gevonden.");
                                        }
                                        else
                                        {
                                                location2 = {lat: 
response.Placemark[0].Point.coordinates[1],
lon: response.Placemark[0].Point.coordinates[0], address:
response.Placemark[0].address};
                                                gDir.load('from: ' + 
location1.address + ' to: ' +
location2.address);

                                                if (showmap == "map")
                                                {
                                                        // Show the map
                                                        map = new 
GMap2(document.getElementById("map_canvas"));
                                                        map.addControl(new 
GLargeMapControl());
                                                }
                                                else
                                                {
                                                        
document.getElementById("map_canvas").innerHTML = "";
                                                        map = null;
                                                }
                                                if (route == "desc")
                                                {
                                                        // Show the route
                                                        directionsPanel = 
document.getElementById("route");
                                                        
directionsPanel.innerHTML = "Route beschrijving:<br>";
                                                }
                                                else
                                                {
                                                        
document.getElementById("route").innerHTML = "";
                                                        directionsPanel = null;

                                                }
                                                directions = new 
GDirections(map, directionsPanel);
                                                directions.load("from: " +  
location1.address + " to: " +
location2.address, {travelMode:G_TRAVEL_MODE_WALKING});
                                        }
                                });
                        }
                });
        }

        </script>
</head>

<body onload="initialize()">


        <form action="#" onsubmit="showLocation(); return false;">
                <p><input name="address1" type="text" size="45" value="" 
/><input
name="latitude1" type="text" size="20" value="" /><input
name="longitude1" type="text" size="20" value="" /><br>
                <input name="address2" type="text" size="45" /><input
name="latitude2" type="text" size="20" value="" /><input
name="longitude2" type="text" size="20" value="" /><br>
                <input name="afstand" type="text" size="7" value="" /></p></p>
        <input type="submit" value="Calculatie afstand" />
        </form>

   <div id="map_canvas" style="width: 674px; height: 389px;
float:left; border: 1px solid black"></div>
   <div id="route" style="width: 50%; height:480px; float:left;
border; 1px solid black; "></div>
     <br/>

</body>
</html>


On 8 jan, 21:16, "[email protected]" <[email protected]>
wrote:
> Hi,
>
> I'm a newbie in using google-maps and java.  I've been able to load a
> route and also get the distance route.getDistance.
> The strange thing is that, when I GDirectionsload(from - to,
> travelmode:G_TRAVEL_MODE_WALKING) and the same with
> G_TRAVEL_MODE_DRIVING) I get a different result on my map and
> directionpanel, but when I call getDistance I always get the same
> distance.
> It's even stranger that the distance in the directionpanel is always
> different than the distance with getDistance.
> Can anyone tell me what the reason is, and how I can get the correct
> distance.
>
> Kind regards
> Bart Syryn
-- 
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