}
         }
     }
     // end of 1st iteration. found time and distance
 }
 if ($i == 7) {
     $org = array();
     $org = getCoord($finarr[$i]);
     //echo $org[0]['latitude'];
     //echo $org[0]['longitude'];
     $des = array();
     $des = getCoord($finarr[$i + 1]);
     //echo $des[0]['latitude'];
     //echo $des[0]['longitude'];
     $marker3 = new Marker();
     $marker3->setPrefixJavascriptVariable('marker_');
     $marker3->setPosition($org[0]['latitude'], $org[0]['longitude'], true);
     $marker3->setAnimation(Animation::DROP);
     $marker3->setOption('clickable', true);
     $marker3->setOption('flat', true);
     $marker3->setOptions(array('clickable' => true, 'flat' => true));
     $map->addMarker($marker);
     $marker4 = new Marker();
     $marker4->setPrefixJavascriptVariable('marker_two');
     $marker4->setPosition($des[0]['latitude'], $des[0]['longitude'], true);
     $marker4->setAnimation(Animation::DROP);
     $marker4->setOption('clickable', true);
     $marker4->setOption('flat', true);
     $marker4->setOptions(array('clickable' => true, 'flat' => true));
     $map->addMarker($marker4);
     // trying directions
function getMarker2($orglat, $orglong, $deslat, $deslong)
{
    //creating map
    $map = new Map();
    $map->setPrefixJavascriptVariable('map_');
    $map->setHtmlContainerId('map_canvas');
    $map->setAsync(false);
    $map->setAutoZoom(false);
    $map->setCenter(37.806381, -122.415468, true);
    $map->setMapOption('zoom', 16);
    $map->setBound(-2.1, -3.9, 2.6, 1.4, true, true);
    $map->setMapOption('mapTypeId', MapTypeId::ROADMAP);
    $map->setMapOption('mapTypeId', 'roadmap');
    $map->setMapOption('disableDefaultUI', true);
    $map->setMapOption('disableDoubleClickZoom', true);
    $map->setMapOptions(array('disableDefaultUI' => true, 'disableDoubleClickZoom' => true));
    $map->setStylesheetOption('width', '600px');
    $map->setStylesheetOption('height', '600px');
    $map->setStylesheetOptions(array('width' => '1000px', 'height' => '800px'));
    $map->setLanguage('en');
    //creating marker
    $marker3 = new Marker();
    $marker3->setPrefixJavascriptVariable('marker_');
    $marker3->setPosition($orglat, $orglong, true);
    $marker3->setAnimation(Animation::DROP);
    $marker3->setOption('clickable', true);
    $marker3->setOption('flat', true);
    $marker3->setOptions(array('clickable' => true, 'flat' => true));
    $map->addMarker($marker);
    $marker4 = new Marker();
    $marker4->setPrefixJavascriptVariable('marker_two');
    $marker4->setPosition($deslat, $deslong, true);
    $marker4->setAnimation(Animation::DROP);
    $marker4->setOption('clickable', true);
    $marker4->setOption('flat', true);
    $marker4->setOptions(array('clickable' => true, 'flat' => true));
    $map->addMarker($marker4);
    // trying directions
    $directions = new Directions(new CurlHttpAdapter());
    $request = new DirectionsRequest();
    // Set your origin
    $request->setOrigin($marker3->getPosition(), true);
    // Set your destination
    $request->setDestination($marker4->getPosition(), true);
    $response = $directions->route($request);
    // Get the routes
    $routes = $response->getRoutes();
    // Iterate each routes
    foreach ($routes as $route) {
        // Get the bound
        $bound = $route->getBound();
        // Get the copyrights
        $copyrights = $route->getCopyrights();
        // Get the legs
        $legs = $route->getLegs();
        // Get the summary
        //$summary = $route->getSummary();
        //print_r ($summary);
        foreach ($legs as $leg) {
            // Gets the distance
            $distance = $leg->getDistance();
            //$dist = (String)$distance;
            print_r($distance);
            // Gets the duration
            $duration = $leg->getDuration();
            print_r($duration);
            //summary
            //$summary = $leg->getSummary();
            //print_r ($summary);
            // Gets the directions steps.
            $steps = $leg->getSteps();
            // Iterate each step
            foreach ($steps as $step) {
                // Gets the encoded polyline.
                $encodedPolyline = $step->getEncodedPolyline();
                $map->addEncodedPolyline($encodedPolyline);
            }
        }
    }
    // end of 1st iteration. found time and distance
    //printing the map
    $mapHelper = new MapHelper();
    echo $mapHelper->renderHtmlContainer($map);
    echo $mapHelper->renderJavascripts($map);
}