From: maxious Date: Wed, 16 Mar 2011 08:18:49 +0000 Subject: Round distances to 2 decimal place kilometers X-Git-Url: https://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=b5c5993a2a28a6141d107876b198f8e32c720fcd --- Round distances to 2 decimal place kilometers --- --- a/common-geo.inc.php +++ b/common-geo.inc.php @@ -51,7 +51,7 @@ if ($collapsible) $output.= ''; 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/common-template.inc.php +++ b/common-template.inc.php @@ -63,7 +63,12 @@ } if (navigator.geolocation) { - navigator.geolocation.getCurrentPosition(success, error); +var options = { + enableHighAccuracy: false, + timeout: 60000, + maximumAge: 10000 +} + navigator.geolocation.getCurrentPosition(success, error, options); } "; --- a/common.inc.php +++ b/common.inc.php @@ -129,5 +129,33 @@ { return str_replace(")", "", str_replace("(", "
", $input)); } + +function sksort(&$array, $subkey="id", $sort_ascending=false) { + + if (count($array)) + $temp_array[key($array)] = array_shift($array); + + foreach($array as $key => $val){ + $offset = 0; + $found = false; + foreach($temp_array as $tmp_key => $tmp_val) + { + if(!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) + { + $temp_array = array_merge( (array)array_slice($temp_array,0,$offset), + array($key => $val), + array_slice($temp_array,$offset) + ); + $found = true; + } + $offset++; + } + if(!$found) $temp_array = array_merge($temp_array, array($key => $val)); + } + + if ($sort_ascending) $array = array_reverse($temp_array); + + else $array = $temp_array; +} ?> --- a/index.php +++ b/index.php @@ -19,6 +19,7 @@
  • Timetables - Routes
  • Routes By Final Destination
  • Routes By Number
  • +
  • Stops By Suburb
  • Nearby Routes
  • '; -echo '