Google Maps: Clickable PolyLine using direction service

 Clickable  PolyLine using direction service

=====================================================
var directionsService = new google.maps.DirectionsService();
    var request = {
        origin : point1,
        destination : point2,
        provideRouteAlternatives : false,
        travelMode : google.maps.DirectionsTravelMode.WALKING
    //travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    var polyline = new google.maps.Polyline({
                 path: [],
                 strokeColor: '#6A5ACD',
                 strokeOpacity : 0.8,
                 strokeWeight: 5
    });
    directionsService.route(request, function(result, status) {
                 if (status == google.maps.DirectionsStatus.OK) {
                       var path = result.routes[0].overview_path;
                       var legs = result.routes[0].legs;
                        for (i=0;i<legs.length;i++) {
                             var steps = legs[i].steps;
                             for (j=0;j<steps.length;j++) {
                                  var nextSegment = steps[j].path;
                                  for (k=0;k<nextSegment.length;k++) {
                                         polyline.getPath().push(nextSegment[k]);
                                  }
                             }
                         }
                         for (i = 0; i < legs.length; i++) {
                           total += legs[i].distance.value;
                           time += legs[i].duration.value;
                        }
                        total = total / 1000;
                        time = time / 60;
                        routePointArray[routePointArray.length - 1].setWalkDistance(total);
                        routePointArray[routePointArray.length - 1].setWalkTime(time);
                        routePointArray[routePointArray.length - 1].setPolyline(polyline);
                         polyline.setMap(map);
                        totalWalkDistanceTime();
                 }
     });
    
}

=====================================================

Comments

Popular posts from this blog

Read Images from a xlsx file using Apache POI

Read Excel using Apache POI - Exception in thread "main" org.apache.poi.poifs.filesystem.OfficeXmlFileException:

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'