/** * Get stops near a location * @param double $latitude * @param double $longitude * @return array */ public function StopsNearLocation($latitude = false, $longitude = false) { if (!$latitude) { throw new Exception("Cannot fetch " . __METHOD__ . " - no latitude given"); } if (!$longitude) { throw new Exception("Cannot fetch " . __METHOD__ . " - no longitude given"); } $query = "SELECT\r\n\t\t\t\t\t\tstop_id,\r\n\t\t\t\t\t\tstop_name,\r\n\t\t\t\t\t\tstop_lat,\r\n\t\t\t\t\t\tstop_lon,\r\n\t\t\t\t\t\twheelchair_boarding, (\r\n\t\t\t\t\t\t\t 3959 * acos (\r\n\t\t\t\t\t\t\t cos ( radians(" . $latitude . ") )\r\n\t\t\t\t\t\t\t * cos( radians( stop_lat ) )\r\n\t\t\t\t\t\t\t * cos( radians( stop_lon ) - radians(" . $longitude . ") )\r\n\t\t\t\t\t\t\t + sin ( radians(" . $latitude . ") )\r\n\t\t\t\t\t\t\t * sin( radians( stop_lat ) )\r\n\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t) AS distance\r\n\t\t\t\t\t\tFROM au_wa_stops\r\n\t\t\t\t\t\tWHERE location_type = 1\r\n\t\t\t\t\t\tHAVING distance < 3\r\n\t\t\t\t\t\tORDER BY distance\r\n\t\t\t\t\t\tLIMIT 0 , 50"; $result = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE); $return = array(); foreach ($result as $row) { $row = $row->getArrayCopy(); $row['provider'] = $this->provider; $row['distance'] = vincentyGreatCircleDistance($row['stop_lat'], $row['stop_lon'], $latitude, $longitude); $return[] = $row; } return $return; }
$response["success"] = 0; $response["message"] = "Post data was empty."; die(json_decode($response)); } $con = mysqli_connect("localhost", "root", "WhatHappendPWD.", "whathappend"); if (mysqli_connect_error()) { echo "failed to connect" . mysqli_connect_error(); } $query = "SELECT `id`, `post`, `user`, `long`, `lat`, `range`, `timestamp` FROM posts ORDER BY id DESC"; if ($result = $con->query($query)) { $response["success"] = 1; $response["message"] = "Posts available"; $response["posts"] = array(); /* fetch associative array */ while ($row = $result->fetch_assoc()) { $distance = vincentyGreatCircleDistance($long, $lat, $row["long"], $row["lat"]); if ($distance < $range && $distance < $row["range"]) { $post = array(); $post["id"] = $row["id"]; $post["username"] = $row["user"]; $post["post"] = $row["post"]; $post["longitude"] = $row["long"]; $post["latitude"] = $row["lat"]; $post["timestamp"] = $row["timestamp"]; $post["distance"] = $distance; //update our repsonse JSON data array_push($response["posts"], $post); } } $result->free(); //Check if user wants to sort by distance or timestamp
function closestDriver($cLat, $cLng, $dDay, &$dArray) { if ($cLat == null || $cLng == null) { //echo "Invalid location </br>"; return 0; } else { $closestDriver = 0; $sDistance = 6371000; $cDistance = 6371000; //echo $cLat.' '.$cLng.'</br>'; foreach ($dArray as $key => $driver) { $driverID = $driver[0]; $driverLat = $driver[1]; $driverLng = $driver[2]; $driverSchedule = $driver[3]; $driverScheduleArray = explode(",", $driverSchedule); // Check delivery Day if (in_array($dDay, $driverScheduleArray)) { //echo $driverID.' '; $cDistance = vincentyGreatCircleDistance($cLat, $cLng, $driverLat, $driverLng); if ($cDistance < $sDistance) { $closestDriver = $driverID; $sDistance = $cDistance; } } else { //echo "($driverID) I dont work that day ($driverSchedule | $dDay | ) </br>"; } //echo $sDistance.' '.$cDistance.'</br>'; } //echo $closestDriver.'</br>'; return $closestDriver; } }
/** * Get stops near a location * @param double $latitude * @param double $longitude * @return array */ public function StopsNearLocation($latitude = null, $longitude = null) { if ($latitude == null) { throw new Exception("Cannot fetch " . __METHOD__ . " - no latitude given"); } if ($longitude == null) { throw new Exception("Cannot fetch " . __METHOD__ . " - no longitude given"); } $parameters = array("latitude" => $latitude, "longitude" => $longitude); $return = array(); foreach ($this->fetch("nearme", $parameters) as $row) { $row['result']['location_name'] = trim($row['result']['location_name']); if ($row['result']['transport_type'] == "train" || preg_match("@Railway@i", $row['result']['location_name'])) { $placeData = array("stop_id" => $row['result']['stop_id'], "stop_name" => $row['result']['location_name'], "stop_lat" => $row['result']['lat'], "stop_lon" => $row['result']['lon'], "wheelchair_boarding" => 0, "location_type" => 1); /** * Check if this is stored in the database, and add it if it's missing */ if (!in_array($row['result']['location_name'], $this->ignore_stops) && $row['result']['stop_id'] < 10000 && !preg_match("@#([0-9]{0,3})@", $row['result']['location_name'])) { $query = sprintf("SELECT stop_id FROM %s_stops WHERE stop_id = %d LIMIT 1", self::DB_PREFIX, $row['result']['stop_id']); $result = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE); if ($result->count() === 0) { $Insert = $this->db->insert(sprintf("%s_stops", self::DB_PREFIX)); $Insert->values($placeData); $selectString = $this->db->getSqlStringForSqlObject($Insert); $this->adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE); } $placeData['distance'] = vincentyGreatCircleDistance($row['result']['lat'], $row['result']['lon'], $latitude, $longitude); $placeData['provider'] = $this->provider; if ($placeData['distance'] <= 10000) { // Limit results to 10km from provided lat/lon $return[] = $placeData; } } } } return $return; }
/** * Get stops near a location * @param double $latitude * @param double $longitude * @return array */ public function StopsNearLocation($latitude = null, $longitude = null) { if ($latitude == null) { throw new Exception("Cannot fetch " . __METHOD__ . " - no latitude given"); } if ($longitude == null) { throw new Exception("Cannot fetch " . __METHOD__ . " - no longitude given"); } $query = "SELECT\r\n stop_id,\r\n stop_name,\r\n stop_lat,\r\n stop_lon,\r\n wheelchair_boarding, (\r\n 3959 * acos (\r\n cos ( radians(" . $latitude . ") )\r\n * cos( radians( stop_lat ) )\r\n * cos( radians( stop_lon ) - radians(" . $longitude . ") )\r\n + sin ( radians(" . $latitude . ") )\r\n * sin( radians( stop_lat ) )\r\n )\r\n ) AS distance\r\n FROM %s_stops\r\n WHERE location_type = 1\r\n HAVING distance < 3\r\n ORDER BY distance\r\n LIMIT 0 , 50"; $query = sprintf($query, static::DB_PREFIX); $result = $this->adapter->query($query, Adapter::QUERY_MODE_EXECUTE); $return = array(); foreach ($result as $row) { $row = $row->getArrayCopy(); $row['provider'] = $this->provider; $row['distance'] = vincentyGreatCircleDistance($row['stop_lat'], $row['stop_lon'], $latitude, $longitude); $return[] = $row; } return $return; }
function getReportsFromDB($longitude, $latitude, $max_distance, $timestamp, $past_window, &$result) { $collection = Config::report_col; $start_time = $timestamp - 60 * $past_window; // past_window is in minutes $end_time = $timestamp; $query = array('time' => array('$gte' => (string) $start_time, '$lte' => (string) $end_time), 'RealTF' => array('$ne' => 'false')); $sort_filter = array("time" => -1); if (!mongodbFind($collection, $query, $cursor)) { return false; } $result = array(); foreach ($cursor as $doc) { $dist = vincentyGreatCircleDistance($latitude, $longitude, $doc['reportLatitude'], $doc['reportLongitude']); if ($dist <= $max_distance) { $report = array('reportLatitude' => (double) $doc['reportLatitude'], 'reportLongitude' => (double) $doc['reportLongitude'], 'address' => $doc['address'], 'type' => $doc['type'], 'severity' => $doc['severity'], 'timestamp' => $doc['time'], 'comments' => $doc['comments'], 'reliability' => 1.0 - (double) $doc['ProbabilityRealTF']); $result[] = $report; } } return true; }