views:

38

answers:

1

Hi People, I'm starting with a project that use GM api. I need to create routes form the tracklogs from vehicles, but for some reason doesn't work.

This is the code, I'm calling the startMap function first, and then addRouteWaypoints. The map and waypoinps are working fine, but the route is not displayed.

///

var map = null;

//----------------------------------------------------------------------------
function startMap() {

    if (GBrowserIsCompatible()) {

        map = new GMap2(document.getElementById("myMap"));
        map.setMapType(G_NORMAL_MAP);
        map.setCenter(new GLatLng(-34.40, -58.90), 11);
        map.addControl(new GSmallMapControl());
        map.setUIToDefault();
    }

}

//----------------------------------------------------------------------------
function addRouteWaypoints(waypoints) {
    try {

        var wps = new Array();

        for (var i = 0; i < waypoints.split(';').length - 2; i++) {

            lat = waypoints.split(';')[i].split(',')[0];
            lng = waypoints.split(';')[i].split(',')[1];

            //these 2 lines are for test...
            var marker = new GMarker(new GLatLng(lat, lng));
            map.addOverlay(marker);

            latProx = waypoints.split(';')[i + 1].split(',')[0];
            lngProx = waypoints.split(';')[i + 1].split(',')[1];

            wps[i] = new Array(new GLatLng(lat, lng), new
                GLatLng(latProx, lngProx));
        }

        //directionsPanel = document.getElementById("div_DirectionsPanel");
        directions = new GDirections(map);
        GEvent.addListener(
            directions,
            'error',
            function() {
                alert(directions.getStatus().code);
            }
        );

        directions.loadFromWaypoints(wps, { getPolyline: true,
        getSteps: true, travelMode: G_TRAVEL_MODE_DRIVING, preserveViewport:
            false, locale: 'es_ES' });
    }
    catch (err) {
        alert(err.source + ':' + err.message);
    }

}

Thanks.

A: 

Try to just draw a polyline - se GPolyline, create it from array and addOverlay()

killer_PL
Yes, but, I need the lines following the streets, ¿this is posible with polylines?
Ariel Larraburu
Maybe you code works good, but have some points that google maps can't resolve trough streets.
killer_PL
All the points are in Buenos Aires, and previously to try to make the route in my project, I do the same in google maps, with the same waypoints.
Ariel Larraburu