Пример #1
0
 public static function localize($indexMap = 0, $objPlayer = null, $isConnected = false)
 {
     if ($indexMap == 0) {
         if (!$isConnected) {
             $indexMap = $objPlayer->getMapIndex();
         } else {
             $indexMap = $objPlayer->getExitMapIndex();
         }
     }
     include '../../pages/Tableaux_Arrays.php';
     $mapData = self::getMapByIndex($indexMap);
     if ($mapData != false) {
         $baseX = $mapData[2];
         $baseY = $mapData[3];
         if ($isConnected) {
             $chaDataX = ($objPlayer->getX() - $baseX) / 200 / 0.5;
             $chaDataY = ($objPlayer->getY() - $baseY) / 200 / 0.5;
         } else {
             $chaDataX = ($objPlayer->getExitX() - $baseX) / 200 / 0.5;
             $chaDataY = ($objPlayer->getExitY() - $baseY) / 200 / 0.5;
         }
         $view = ["map" => MapHelper::getLibelle($indexMap), "positionX" => floor($chaDataX), "positionY" => floor($chaDataY)];
         return json_encode($view);
     } else {
         return "Position inconnu";
     }
 }
                    //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
        }
    }
    //end of for
    $mapHelper = new MapHelper();
    echo $mapHelper->renderHtmlContainer($map);
    echo $mapHelper->renderJavascripts($map);
}
//submit ends here
function getCoord($node)
{
    include 'dbinfo.inc';
    $rest = array();
    $query3 = "SELECT `latitude`, `longitude` from `nodes` where `node_id`='{$node}'";
    $res3 = mysqli_query($con, $query3) or die("Invalid query: " . mysql_error());
    while ($row = mysqli_fetch_assoc($res3)) {
        $rest[] = $row;
    }
    return $rest;
}
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);
}