Пример #1
0
 function findEndNode($fromID, $lat, $lon, $table)
 {
     $query = "SELECT * FROM {$table}\n\t\t\t\t  WHERE start_lat BETWEEN {$lat}-{$this->Error} AND {$lat}+{$this->Error}\n\t\t\t\t  AND start_lon BETWEEN {$lon}-{$this->Error} AND {$lon}+{$this->Error}";
     //		$query = "SELECT * FROM spat_nodes WHERE MBRContains(ST_GeomFromText('Polygon(({$lon}-{$this->Error},{$lat}-{$this->Error},{$lon}+{$this->Error},{$lat}+{$this->Error})'),latlon) AND start = '1'";
     $result = $this->Conn->query($query);
     if ($result) {
         if (mysqli_num_rows($result) > 0) {
             while ($row = $result->fetch_array()) {
                 $toID = $row['id'];
                 echo "{$toID} ";
                 $distance = haversineGreatCircleDistance(floatval($lat), floatval($lon), floatval($row['start_lat']), floatval($row['start_lon']));
                 $query = "INSERT INTO southwest_edges VALUES('{$fromID}','{$toID}')";
                 $this->Conn->query($query);
             }
         }
     }
 }
Пример #2
0
     $lastlon = 0;
     $lastdistance = 0;
     $semaine[$tabjour[0]]["debut"] = 0;
     $lastjour = $tabjour[0];
     $i = 0;
     $trajet = array();
     $debut = 0;
     $fin = 0;
     $semaine[$tabjour[0]]["date"] = affichedateiso($tabjour[0]) . " - " . jourfr(dayOfWeek(strtotime($tabjour[0])) - 1);
 }
 //$semaine[$tabjour[0]]["km"]+=(int)$tblconduite["distance_next"]/1000;
 $distance = 0;
 if ($lastlat != $tblconduite["latitude"] && $lastlon != $tblconduite["longitude"]) {
     if ($lastlat != 0 && $lastlon != 0) {
         //print "ici2";
         $distance = haversineGreatCircleDistance($lastlat, $lastlon, $tblconduite["latitude"], $tblconduite["longitude"]) / 1000;
         $semaine[$tabjour[0]]["km"] += round($distance, 2);
         $totaldistance += $semaine[$tabjour[0]]["km"];
     }
 }
 $semaine[$tabjour[0]]["vitessemax"] = $semaine[$tabjour[0]]["vitessemax"] > vitessekmh($tblconduite["speed"]) ? $semaine[$tabjour[0]]["vitessemax"] : vitessekmh($tblconduite["speed"]);
 // if(($lastspeed!=$tblconduite["speed"]&&$lastspeed==0)||($lastdistance!=$distance&&$lastdistance==0)){
 if ($lastspeed != $tblconduite["speed"] && $lastspeed == 0 || $lastlat != round($tblconduite["latitude"], 4) && $lastlon != round($tblconduite["longitude"], 4) && !$first && $tblconduite["speed"] != 0) {
     $semaine[$tabjour[0]]["debut"] = $semaine[$tabjour[0]]["debut"] == 0 ? $tblconduite["time"] : $semaine[$tabjour[0]]["debut"];
     $semaine[$tabjour[0]]["fin"] = 0;
     $debut = strtotime($tblconduite["time"]);
 }
 if ($lastspeed != $tblconduite["speed"] && $tblconduite["speed"] == 0 && $lastspeed != 0 || $lastdistance != $distance && $distance == 0 && $lastdistance != 0) {
     $semaine[$tabjour[0]]["fin"] = $tblconduite["time"];
     $fin = strtotime($tblconduite["time"]);
     if ($semaine[$tabjour[0]]["fin"] != "" && $semaine[$tabjour[0]]["debut"] != "") {
Пример #3
0
 if ($argument2 == "0") {
     $sql = "\n\t\tSELECT items.itemID, items.name, items.about, items.value, items.power,items.pin,servers.adres,servers.serveradres FROM items \n\t\tLEFT JOIN servers\n\t\tON items.serverID =servers.serverID\n\t\tWHERE name='" . $argument1 . "'";
 } else {
     $sql = "\n\t\tSELECT a.itemID, a.name, a.about, a.value,a.power, b.lat,b.lon \n\t\tFROM items a \n\t\tINNER JOIN poi b ON b.id = a.locID \n\t\tWHERE a.locID>0\n\t";
 }
 $result = mysqli_query($conn, $sql);
 header("Content-type: text/xml");
 $xml_output = "<?xml version=\"1.0\"?>\n";
 $xml_output .= "<items>\n";
 if (mysqli_num_rows($result) > 0) {
     // output data of each row
     while ($row = mysqli_fetch_assoc($result)) {
         $vafstand = "";
         $check = 0;
         if (isset($_GET['lat']) && isset($_GET['lon'])) {
             $vafstand = haversineGreatCircleDistance($argument3 = $_GET['lat'], $argument4 = $_GET['lon'], $row["lat"], $row["lon"]);
             if ($vafstand < $afstand) {
                 $check = 1;
             }
         } else {
             $check = 1;
         }
         if ($check == 1) {
             $xml_output .= "<item>\n";
             $afwijking = $row["value"] * $schommeling;
             $value = rand($row["value"] - $afwijking, $row["value"] + $afwijking);
             printName("id", $row["itemID"]);
             printName("name", $row["name"]);
             printName("about", $row["about"]);
             if (is_null($row["adres"]) or is_null($row["pin"])) {
                 printName("value", $value);
Пример #4
0
    echo $itm->itm_latitude;
    ?>
,<?php 
    echo $itm->itm_longitude;
    ?>
&oe=UTF-8&ie=UTF-8"><i class="material-icons md-18">place</i><?php 
    echo $itm->itm_latitude;
    ?>
,<?php 
    echo $itm->itm_longitude;
    ?>
</a><?php 
    if ($this->axipi_session->userdata('latitude') && $this->axipi_session->userdata('longitude')) {
        ?>
 (<?php 
        echo haversineGreatCircleDistance($itm->itm_latitude, $itm->itm_longitude, $this->axipi_session->userdata('latitude'), $this->axipi_session->userdata('longitude'));
        ?>
)<?php 
    }
    ?>
</p>
		<a target="_blank" href="http://maps.google.com/maps?q=<?php 
    echo $itm->itm_latitude;
    ?>
,<?php 
    echo $itm->itm_longitude;
    ?>
&oe=UTF-8&ie=UTF-8"><img src="https://maps.googleapis.com/maps/api/staticmap?center=<?php 
    echo $itm->itm_latitude;
    ?>
,<?php 
Пример #5
0
<?php

function haversineGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000)
{
    // convert from degrees to radians
    $latFrom = deg2rad($latitudeFrom);
    $lonFrom = deg2rad($longitudeFrom);
    $latTo = deg2rad($latitudeTo);
    $lonTo = deg2rad($longitudeTo);
    $latDelta = $latTo - $latFrom;
    $lonDelta = $lonTo - $lonFrom;
    $angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) + cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));
    return $angle * $earthRadius;
}
function pythag($latFrom, $latTo, $lTo, $longTo)
{
    $d0 = deg2rad($latFrom - $latTo);
    $d1 = deg2rad($longFrom - $longTo);
    return 6371000 * sqrt(pow($d0, 2) + pow($d1, 2)) / 1609;
}
echo pythag(0, 0, 5, 10);
//$d = deg2rad(10);
//echo pow($d,2);
echo "<br>";
echo haversineGreatCircleDistance(0, 0, 5, 10) / 1609;
Пример #6
0
function get_posts_in_vicinity($lat, $long, $course)
{
    global $db;
    $db->Prepare("SELECT * FROM users");
    $db->Execute();
    $users = array();
    while ($result = $db->Fetch()) {
        $dist = haversineGreatCircleDistance($lat, $long, $result["lat"], $result["long"]);
        if ($dist < 150) {
            array_push($users, $result["id"]);
        }
    }
    $ret = array();
    foreach ($users as $u) {
        $db->Prepare("SELECT * FROM posts WHERE user_id='\$0' AND course_id='\$1'");
        $db->Execute($u, $course);
        while ($result = $db->Fetch()) {
            array_push($ret, $result);
        }
    }
    $temp = array();
    foreach ($ret as $key => $row) {
        $temp[$key] = $row['post_time'];
    }
    array_multisort($temp, SORT_DESC, $ret);
    return $ret;
}
Пример #7
0
 function calcDistance($points)
 {
     $distance = 0;
     for ($i = 0; $i < sizeof($points) - 1; $i++) {
         $distance += haversineGreatCircleDistance($points[$i][1], $points[$i][0], $points[$i + 1][1], $points[$i + 1][0]);
     }
     return $distance;
 }
Пример #8
0
 * @param float $longitudeFrom Longitude of start point in [deg decimal]
 * @param float $latitudeTo Latitude of target point in [deg decimal]
 * @param float $longitudeTo Longitude of target point in [deg decimal]
 * @param float $earthRadius Mean earth radius in [m]
 * @return float Distance between points in [m] (same as earthRadius)
 */
function haversineGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000)
{
    // convert from degrees to radians
    $latFrom = deg2rad($latitudeFrom);
    $lonFrom = deg2rad($longitudeFrom);
    $latTo = deg2rad($latitudeTo);
    $lonTo = deg2rad($longitudeTo);
    $latDelta = $latTo - $latFrom;
    $lonDelta = $lonTo - $lonFrom;
    $angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) + cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));
    return $angle * $earthRadius;
}
$center_lat = -9.2890222;
$center_lng = -35.543886;
$lat = -9.282627;
$lng = -35.545431;
// test with your arccosine formula
$distance = 6371 * acos(cos(deg2rad($center_lat)) * cos(deg2rad($lat)) * cos(deg2rad($lng) - deg2rad($center_lng)) + sin(deg2rad($center_lat)) * sin(deg2rad($lat)));
print $distance;
// prints 9.662174538188
echo "</br></br>";
// test with my haversine formula
$distance = haversineGreatCircleDistance($center_lat, $center_lng, $lat, $lng, 6371);
print $distance;
// prints 9.6621745381693
Пример #9
0
function suggestions()
{
    if (connected()) {
        //On attrape les infos qu'on veut
        $user_info = getUserDetails($_SESSION['id']);
        $user_events = getMemberEvents($_SESSION['id']);
        $events = getEvents($_SESSION['id']);
        if (empty($events) || empty($user_events) || empty($user_info) || count($events) < 3) {
            return [];
        }
        //Enlève les évents auquel il participe.
        foreach ($events as $key => $value) {
            foreach ($user_events as $cle => $valeur) {
                if (count($events) - count($user_events) > 3) {
                    // Teste s'il y a assez d'évènements pour faire 3 recommendations
                    if ($value["id"] == $valeur['id']) {
                        unset($events[$key]);
                    }
                }
            }
            //Ajoute les coordonnées à chaue événement auquel il ne participe pas.
            if (!isset($events[$key])) {
                continue;
            }
            $event_adress = getAdressCoord($value['id']);
            $events[$key]['coordonnee_long'] = $event_adress['coordonnee_long'];
            $events[$key]['coordonnee_lat'] = $event_adress['coordonnee_lat'];
            $events[$key]['lien_photo'] = generateMediaLink($value['id'], $value['type']);
        }
        // ======= BIENTOT ========
        //Tri par date des evenements
        function date_compare($a, $b)
        {
            $t1 = strtotime($a['debut']);
            $t2 = strtotime($b['debut']);
            return $t1 - $t2;
        }
        usort($events, 'date_compare');
        $timeRec = $events[0];
        // ======= TYPE ========
        //Classement des Types par ID.
        $types = [];
        foreach ($user_events as $key => $value) {
            array_push($types, $value["type"]);
        }
        $types = array_count_values($types);
        $top_type = array_keys($types, max($types));
        //Choix de l'évènement par Type.
        foreach ($events as $key => $value) {
            if (in_array($value['type'], $top_type)) {
                $typeRec = $value;
                if ($timeRec['id'] == $typeRec['id']) {
                    continue;
                } else {
                    break;
                }
            }
        }
        //Aléatoire sinon.
        if (!isset($typeRec)) {
            $typeRec = $events[rand(0, count($events) - 1)];
            while ($timeRec['id'] == $typeRec['id']) {
                $typeRec = $events[rand(0, count($events) - 1)];
            }
        }
        // ======= PROXIMITE ========
        if (isset($user_info['coordonnee_long']) && isset($user_info['coordonnee_lat'])) {
            // Addresse renseignée.
            //Tri par distance (grande sphère)
            foreach ($events as $key => $value) {
                $events[$key]['distance'] = haversineGreatCircleDistance(floatval($user_info['coordonnee_lat']), floatval($user_info['coordonnee_long']), floatval($events[$key]['coordonnee_lat']), floatval($events[$key]['coordonnee_long']));
            }
            function distance_compare($a, $b)
            {
                return $a['distance'] - $b['distance'];
            }
            usort($events, 'distance_compare');
            $proxRec = $events[0];
            if ($proxRec['id'] == $typeRec['id']) {
                $proxRec = $events[1];
            }
        } else {
            //Addresse non renseignée. Donc aléatoire.
            $proxRec = $events[rand(0, count($events) - 1)];
            while ($proxRec['id'] == $typeRec['id'] || $proxRec['id'] == $timeRec['id']) {
                $proxRec = $events[rand(0, count($events) - 1)];
            }
        }
        return [$timeRec, $typeRec, $proxRec];
    } else {
        // 100% radom public events
        $events = getEvents();
        if (count($events) < 3) {
            return [];
        }
        $recs = array_rand($events, 3);
        foreach ($recs as $key => $value) {
            $events[$value]['lien_photo'] = generateMediaLink($value, $events[$value]['type']);
        }
        return [$events[$recs[0]], $events[$recs[1]], $events[$recs[2]]];
    }
}
Пример #10
0
function findlieu($lat, $lon)
{
    $sql = "select lc.*,tlc.libelle as libcat from " . __racinebd__ . "lieu_compte lc inner join " . __racinebd__ . "type_lieu_compte tlc on lc.type_lieu_compte_id=tlc.type_lieu_compte_id where lc.supprimer=0 and compte_id=" . $_SESSION["compte_id"];
    $link = query($sql);
    while ($tbl = fetch($link)) {
        if (haversineGreatCircleDistance($lat, $lon, $tbl["latitude"], $tbl["longitude"]) <= $tbl["rayon"]) {
            if ($tbl["adresse"] == "") {
                $tbl["adresse"] = getAddess($lat, $lon);
                $sql = "update " . __racinebd__ . "lieu_compte set adresse='" . $tbl["adresse"] . "' where lieu_compte_id=" . $tbl["lieu_compte_id"];
                query($sql);
            }
            $tbl["adresse"] = str_replace(", France", "", $tbl["adresse"]);
            return $tbl;
            break;
        }
    }
    return false;
}