Round distances to 2 decimal place kilometers
--- a/common-geo.inc.php
+++ b/common-geo.inc.php
@@ -51,7 +51,7 @@
if ($collapsible) $output.= '</div>';
return $output;
}
-function distance($lat1, $lng1, $lat2, $lng2)
+function distance($lat1, $lng1, $lat2, $lng2, $roundLargeValues = false)
{
$pi80 = M_PI / 180;
$lat1*= $pi80;
@@ -64,7 +64,10 @@
$a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2);
$c = 2 * atan2(sqrt($a) , sqrt(1 - $a));
$km = $r * $c;
- return $km * 1000;
+ if ($roundLargeValues) {
+ if ($km < 1) return floor($km * 1000);
+ else return round($km,2)."k";
+ } else return floor($km * 1000);
}
function decodePolylineToArray($encoded)
{
--- a/stopList.php
+++ b/stopList.php
@@ -63,7 +63,7 @@
timePlaceSettings();
}
echo ' <ul data-role="listview" data-filter="true" data-inset="true" >';
- if (!isset($_REQUEST['firstLetter']) && !$_REQUEST['suburb']) {
+ if (!isset($_REQUEST['firstLetter']) && !$_REQUEST['suburb'] && !$_REQUEST['nearby']) {
foreach (range('A', 'Z') as $letter) {
echo "<li><a href=\"stopList.php?firstLetter=$letter&$listType\">$letter...</a></li>\n";
}
@@ -75,9 +75,9 @@
}
// Sort the stops by name
array_multisort($stopName, SORT_ASC, $stops);
- if (!isset($_REQUEST['suburb'])){
+ if (!isset($_REQUEST['suburb']) && !isset($_REQUEST['nearby'])){
$stops = array_filter($stops, "filterByFirstLetter");
- }
+ }
$stopsGrouped = Array();
foreach ($stops as $key => $row) {
if ((trim(preg_replace("/\(Platform.*/","",$stops[$key][1])) != trim(preg_replace("/\(Platform.*/","",$stops[$key + 1][1]))) || $key + 1 >= sizeof($stops)) {
@@ -90,7 +90,7 @@
if (!startsWith($stopsGrouped['stop_codes'][0], "Wj")) echo '<img src="css/images/time.png" alt="Timing Point" class="ui-li-icon">';
echo '<a href="stop.php?stopids=' . implode(",", $stopsGrouped['stop_ids']) . '">';
if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) {
- echo '<span class="ui-li-count">' . floor(distance($row[2], $row[3], $_SESSION['lat'], $_SESSION['lon'])) . 'm away</span>';
+ echo '<span class="ui-li-count">' . distance($row[2], $row[3], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>';
}
echo bracketsMeanNewLine(trim(preg_replace("/\(Platform.*/","",$row[1])) . '(' . sizeof($stopsGrouped["stop_ids"]) . ' stops)');
echo "</a></li>\n";
@@ -102,7 +102,7 @@
if (!startsWith($row[5], "Wj")) echo '<img src="css/images/time.png" alt="Timing Point" class="ui-li-icon">';
echo '<a href="stop.php?stopid=' . $row[0] . (startsWith($row[5], "Wj") ? '&stopcode=' . $row[5] : "") . '">';
if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) {
- echo '<span class="ui-li-count">' . floor(distance($row[2], $row[3], $_SESSION['lat'], $_SESSION['lon'])) . 'm away</span>';
+ echo '<span class="ui-li-count">' . distance($row[2], $row[3], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>';
}
echo bracketsMeanNewLine($row[1]);
echo "</a></li>\n";
@@ -131,7 +131,6 @@
}
}
echo '</ul>';
- var_dump ($stopsGrouped);
}
include_footer();
?>