johnavinash / jquery-ui-map

Automatically exported from code.google.com/p/jquery-ui-map
0 stars 0 forks source link

Cannot read property 'apply' of undefined #86

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The following code produces an error :  Cannot read property 'apply' of 
undefined. It should show a route on the map between two points. I cannot get 
it to work.. I have also tried gmaps service stuff for route drawing, then i 
get the same error.

var path = new Array();

        var service = new google.maps.DirectionsService();
        var polyline = {};

        var src = new google.maps.LatLng(fromCoordinates[1], fromCoordinates[0]);
        var des = new google.maps.LatLng(toCoordinates[1], toCoordinates[0]);

        service.route({
            origin: src,
            destination: des,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        }, function (result, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                for (var i = 0, len = result.routes[0].overview_path.length; i < len; i++) {
                    path.push(result.routes[0].overview_path[i]);
                }

            }
        });
        var colour = '#0000FF';
        polyline = {
            path: path,
            strokeColor: colour,
            strokeOpacity: 1.0,
            strokeWeight: 4
        };

        $("#map_canvas").gmap('addShape', 'Polyline', polyline);

Original issue reported on code.google.com by k...@it-minds.dk on 30 Aug 2014 at 2:50