/**
  * Get more detailed geocode from OSM
  */
 function geocode()
 {
     $geocode = $this->geocodeString();
     // Do not geocode twice
     $geocoded = $this->geocodeKey();
     if ($this->geocoded == $geocoded) {
         return true;
     } else {
         $geocoder = new \Geocoder\Geocoder();
         $adapter = new \Geocoder\HttpAdapter\CurlHttpAdapter();
         $geocoder->registerProviders(array(new \Geocoder\Provider\OpenStreetMapProvider($adapter)));
         try {
             $geotools = new \League\Geotools\Geotools();
             $cache = new \League\Geotools\Cache\MongoDB();
             $results = $geotools->batch($geocoder)->setCache($cache)->geocode([$geocode])->parallel();
         } catch (Exception $ex) {
             return false;
         }
         if (count($results) > 0) {
             if ($results[0]->getExceptionMessage()) {
                 return false;
             } else {
                 $this->lat = $results[0]->getLatitude();
                 $this->lng = $results[0]->getLongitude();
                 $this->geosource = 'OSM';
                 $this->geocoded = $geocoded;
                 return true;
             }
         } else {
             return false;
         }
     }
 }
Exemple #2
0
    }
}
/**
 * Check version
 */
$columns = $PDO->query('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "' . $database . '" AND TABLE_NAME ="' . PREFIX . 'training"')->fetchAll(PDO::FETCH_COLUMN, 0);
if (!in_array('is_night', $columns)) {
    echo 'Update your installation from v2.3 to v2.4 via update.php.' . NL;
    exit;
}
/**
 * Overview for data
 */
$Routes = $PDO->query('SELECT tr.id, tr.time, tr.s, r.startpoint from ' . PREFIX . 'training tr LEFT JOIN ' . PREFIX . 'route r ON tr.routeid = r.id  WHERE tr.routeid IS NOT NULL AND r.startpoint IS NOT NULL AND startpoint != "7zzzzzzzzz"');
$InsertIsNight = $PDO->prepare('UPDATE ' . PREFIX . 'training SET `is_night` = :val WHERE `id` = :id');
$geotools = new \League\Geotools\Geotools();
$detector = new \Runalyze\Calculation\NightDetector();
while ($Route = $Routes->fetch()) {
    $coord = $geotools->geohash()->decode($Route['startpoint'])->getCoordinate();
    $timepoint = $Route['time'] + 0.5 * $Route['s'];
    $detector->setFrom($Route['time'] + 0.5 * $Route['s'], $geotools->geohash()->decode($Route['startpoint'])->getCoordinate());
    if ($detector->isKnown()) {
        $InsertIsNight->execute(array(':val' => $detector->value() ? 1 : 0, ':id' => $Route['id']));
    }
    echo ".";
}
if (CLI) {
    echo NL . NL;
}
echo 'done;' . NL;
echo NL;
Exemple #3
0
    $locationField = 'point';
    $mainSearchParams['body']['aggs']['events']['geohash_grid']['field'] = 'point';
} else {
    array_push($filters, array('term' => ['eventType' => $type]));
    $mainSearchParams['index'] = 'vehicleevents';
    $mainSearchParams['type'] = 'event';
    $mainSearchParams['body']['aggs']['events']['geohash_grid']['field'] = 'location';
}
array_push($filters, array('geo_bounding_box' => [$locationField => ['top_left' => ['lat' => 37.850636, 'lon' => -122.551841], 'bottom_right' => ['lat' => 37.665367, 'lon' => -122.276801]]]));
if ($route) {
    array_push($filters, array('term' => ['routeTag' => $route]));
}
$mainSearchParams['body']['query']['bool']['must'] = $filters;
$mainSearchParams['body']['aggs']['events']['geohash_grid']['precision'] = 8;
$mainSearchParams['body']['aggs']['events']['geohash_grid']['size'] = 1000;
$mainHits = $client->search($mainSearchParams);
$maxCount = -1;
$mainResults = array();
$geotools = new \League\Geotools\Geotools();
foreach ($mainHits['aggregations']['events']['buckets'] as $mainHitId => $mainHitValue) {
    $geoKey = $mainHitValue['key'];
    $docs = $mainHitValue['doc_count'];
    if ($maxCount == -1) {
        $maxCount = $docs;
    }
    $decodedGeo = $geotools->geohash()->decode($geoKey);
    $lat = $decodedGeo->getCoordinate()->getLatitude();
    $lon = $decodedGeo->getCoordinate()->getLongitude();
    $mainResults[] = array('lat' => $lat, 'lon' => $lon, 'score' => 3 * sprintf("%.5f", $docs / $maxCount));
}
echo json_encode($mainResults);
 /**
  * Affichage de la carte
  *
  * @Method("GET")
  */
 public function indexAction(Request $request)
 {
     //RECUPERATION DES FICHES QUI SONT ACTIVES
     $em = $this->getDoctrine()->getManager();
     $fiches = $em->getRepository('ProjetAppBundle:Fiche')->findBy(array('status' => '1', 'user' => $this->getUser()));
     //CREATION DE LA CARTE
     //        $map = $this->get('ivory_google_map.map');
     $map = new Map();
     $map->setPrefixJavascriptVariable('map_');
     $map->setHtmlContainerId('map_canvas');
     $map->setAsync(false);
     $map->setAutoZoom(true);
     $map->setCenter(-0.3483401, 49.1755575, true);
     $map->setMapOption('zoom', 13);
     $map->setBound(-2.1, -3.9, 2.6, 1.4, true, true);
     $map->setMapOption('mapTypeId', 'roadmap');
     $map->setMapOption('disableDefaultUI', false);
     $map->setMapOption('disableDoubleClickZoom', true);
     $map->setStylesheetOption('width', '1200px');
     $map->setStylesheetOption('height', '700px');
     $map->setLanguage('fr');
     //CREATION D'UN POLYGONE
     $polygon = $this->drawPolygon();
     $tab = array();
     foreach ($fiches as $fiche) {
         //            $polygon->addCoordinate($fiche->getLatitude(),$fiche->getLongitude(),true);
         //            $map->addPolygon($polygon);
     }
     for ($i = 0; $i < count($fiches); $i++) {
         $directions = new Directions(new CurlHttpAdapter());
         $depart = $fiches[$i]->addressString();
         //CREATION D'UNE FENETRE DE DETAILS DES INFORMATIONS
         $infoWindow = $this->InfoWindowMarker($fiches[$i]);
         $infoWindow->setContent('<h1>' . $fiches[$i]->getLibelle() . '</h1><br><address>' . $fiches[$i]->addressString() . '</address><br>');
         //CREATION D'UN MARRKER POUR CHACUNE DES FICHES
         $marker = $this->createMarker($fiches[$i]);
         $marker->setJavascriptVariable('marker_fiche_' . $fiches[$i]->getId());
         //AJOUTER UNE FENETRE DE DETAILS POUR LES MARQUEURS
         $marker->setInfoWindow($infoWindow);
         for ($j = 0; $j < count($fiches); $j++) {
             $arrivee = $fiches[$j]->addressString();
             if ($depart != $arrivee) {
                 //RETROUVER LE POINT DU MILIEU ENTRE DEUX ADRESSES
                 $geotools = new \League\Geotools\Geotools();
                 $coordA = new \League\Geotools\Coordinate\Coordinate([$fiches[$i]->getLongitude(), $fiches[$i]->getLatitude()]);
                 $coordB = new \League\Geotools\Coordinate\Coordinate([$fiches[$j]->getLongitude(), $fiches[$j]->getLatitude()]);
                 $vertex = $geotools->vertex()->setFrom($coordA)->setTo($coordB);
                 $middlePoint = $vertex->middle();
                 //PERSISTE LES MIDPOINTS DANS LA BASE DE DONNEES
                 $ficheMilieu = new FicheMilieu();
                 $ficheMilieu->setLibelle('Milieu entre : ' . $fiches[$i]->getLibelle() . ' et ' . $fiches[$j]->getLibelle());
                 $ficheMilieu->setLongitude($middlePoint->getLongitude());
                 $ficheMilieu->setLatitude($middlePoint->getLatitude());
                 $ficheMilieu->setFicheA($fiches[$i]);
                 $ficheMilieu->setFicheB($fiches[$j]);
                 $coordpolaire = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng=" . $ficheMilieu->getLongitude() . "," . $ficheMilieu->getLatitude() . "&key=AIzaSyDePZt3uyPPCISJtyM5nvkmL_s5YxjcqBo");
                 $json = json_decode($coordpolaire);
                 //                    echo '<pre>';
                 //                    var_dump($json->{'results'}[0]->{'formatted_address'});
                 //                    echo '</pre>';
                 $address = $json->{'results'}[0]->{'formatted_address'};
                 $res = explode(",", $address);
                 $ficheMilieu->setAddress($res[0]);
                 $res2 = explode(" ", $res[1]);
                 $ficheMilieu->setZipcode($res2[1]);
                 $ficheMilieu->setCity($res2[2]);
                 $em = $this->getDoctrine()->getManager();
                 $findFicheMilieu = $em->getRepository('ProjetAppBundle:FicheMilieu')->findByAddress($ficheMilieu->getAddress());
                 if (empty($findFicheMilieu)) {
                     $em->persist($ficheMilieu);
                     $em->flush();
                 }
                 $response = $directions->route($depart, $arrivee);
                 $routes = $response->getRoutes();
                 //BOUCLE QUI PARCOURT LA LISTE DES ROUTES TROUVEES
                 foreach ($routes as $route) {
                     //AJOUTER UN TRAIT SUR LA CARTE POUR LES TRAJETS
                     $polyline = $route->getOverviewPolyline();
                     $polyline->getValue();
                     $couleurs = array('#1abc9c', '#27ae60', '#2980b9', '#8e44ad', '#2c3e50', '#f39c12', '#d35400', '#c0392b', '#7f8c8d');
                     $nbrcouleurs = count($couleurs) - 1;
                     $rand = rand(0, $nbrcouleurs);
                     $lacouleur = $couleurs[$rand];
                     $polyline->setOption('strokeColor', $lacouleur);
                     unset($couleurs[array_search($lacouleur, $couleurs)]);
                     $map->addEncodedPolyline($polyline);
                     $legs = $route->getLegs();
                     foreach ($legs as $leg) {
                         //MISE A JOUR DE LA FENETRE D'INFORMATION DES MARKERS
                         $string = 'Trajet en direction de : ' . $fiches[$j]->getLibelle() . '(' . $leg->getEndAddress() . ')
                         , DISTANCE: ' . $leg->getDistance()->getText() . ' DUREE : ' . $leg->getDuration()->getText() . '<br>';
                         $marker->getInfoWindow()->setContent($marker->getInfoWindow()->getContent() . $string);
                         //                            var_dump("DEPART: " .$leg->getStartAddress().", ARRIVEE: ".$leg->getEndAddress().", DISTANCE: ".$leg->getDistance()->getText()."<br>");
                         $count = $leg->getDistance()->getValue();
                         //                            var_dump($count);
                         $steps = $leg->getSteps();
                         foreach ($steps as $step) {
                             $midPoint = "";
                             //                                if($step->getDistance()->getValue() == $count) {
                             //                                    var_dump("OKOKOKOKOK");
                             //                                } else {
                             //                                    var_dump($step->getDistance()->getValue());
                             //                                }
                             //                        var_dump("STEP");
                             //                        var_dump($step->getInstructions());
                             //                                var_dump($step->getStartLocation());
                             $marker3 = new Marker();
                             //                                $marker2 = new Marker();
                             $marker3->setPosition($step->getStartLocation()->getLatitude(), $step->getStartLocation()->getLongitude(), true);
                             //                                array_push ($tabMarker,$marker);
                             //                                $marker2->setPosition($step->getEndLocation()->getLatitude(),$step->getEndLocation()->getLongitude(),true);
                             //$marker->setAnimation('bounce');
                             // $marker2->setAnimation('bounce');
                             //$map->addMarker($marker3);
                             //$map->addMarker($marker2);
                         }
                     }
                 }
             }
         }
         //            foreach($tab as $value){
         //                $polygon->addCoordinate($value->getLongitude(),$value->getLatitude(),true);
         //            }
         //            $map->addPolygon($polygon);
         $map->addMarker($marker);
     }
     $tabMarker = $this->displayMiddlePoint($fiches);
     foreach ($tabMarker as $markers) {
         $map->addMarker($markers);
     }
     //        $event = new Event();
     //        $event->setInstance($map->getJavascriptVariable());
     //        $event->setEventName("click");
     //        $handle = 'function(e){
     //            var pos = e.latLng;
     //            var direction = new google.maps.DirectionsService();
     //            var directionsDisplay = new google.maps.DirectionsRenderer;
     //
     //            var contentString = "Marker";
     //                oInfo = new google.maps.InfoWindow();
     //
     //            directionsDisplay.setMap(this);
     //            directionsDisplay.setPanel(document.getElementById("directionsPanel"));
     //
     //            var marker = new google.maps.Marker({
     //                position: pos,
     //                animation: google.maps.Animation.DROP,
     //                title: "Uluru (Ayers Rock)",
     //                map: this
     //            });
     //            google.maps.event.addListener(marker, \'click\', function() {
     //                  oInfo.setContent( "lol");
     //                oInfo.open(this, marker);
     //            });
     //
     //             var request = {
     //                origin:marker.position,
     //                destination:"46 rue jules ferry 14000 caen",
     //                travelMode: google.maps.TravelMode.DRIVING
     //            };
     //
     //            direction.route(request, function(response, status) {
     //                if (status === google.maps.DirectionsStatus.OK) {
     //                    directionsDisplay.setDirections(response);
     //                } else {
     //                    window.alert(\'Directions request failed due to \' + status);
     //                }
     //            });
     //
     //            console.log(marker_fiche_2);
     //        }';
     //        $event->setHandle($handle);
     //
     //        $map->getEventManager()->addDomEvent($event);
     return $this->render('ProjetAppBundle:Map:index.html.twig', array('map' => $map, 'fiches' => $fiches));
 }
Exemple #5
0
 /**
  * Add marker
  * @param float $Lat
  * @param float $Lng
  * @param string $Icon JS-icon
  * @param string $Tooltip [optional]
  */
 public final function addMarkerGeohash($Geohash, $Icon, $Tooltip = '')
 {
     $geotools = new \League\Geotools\Geotools();
     $decoded = $geotools->geohash()->decode($Geohash);
     $this->Marker[] = 'L.marker([' . $decoded->getCoordinate()->getLatitude() . ',' . $decoded->getCoordinate()->getLongitude() . '], {icon: ' . $Icon . ', tooltip: "' . $Tooltip . '"})';
 }