-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetCat.classes.php
More file actions
86 lines (73 loc) · 1.9 KB
/
getCat.classes.php
File metadata and controls
86 lines (73 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
// This file contains the classes used by getCat.php - they are mostly just data storage, with
// some simple computations as well
//make the map of geopoints to buildings
class GeoPoint {
public $lat;
public $lon;
function __construct($lat, $lon) {
$this->lat = $lat;
$this->lon = $lon;
}
}
// item class.
class Item {
public $lat;
public $lon;
public $info;
public $distance;
public $floor;
function __construct($latItem, $lonItem, $info, $floor=-9) {
$this->lat = $latItem;
$this->lon = $lonItem;
$this->info = $info;
$this->floor = $floor;
}
}
// building class, this may be a useful datatype
class Building {
public $lat;
public $lon;
public $name;
public $items;
public $distance;
function __construct($latItem, $lonItem, $name) {
$this->lat = $latItem;
$this->lon = $lonItem;
$this->name = $name;
$this->items = array();
global $lat; global $lon;
if ($lat == -1) $this->distance = -1;
else $this->distance = $this->distance($lat, $lon);
}
//
function distance($lat1, $lon1, $unit = "m") {
// reassign the variables to work with this existing code without making it confusing
$lat2 = $this->lat;
$lon2 = $this->lon;
// now let's convert it to actual lat/lons
$lat2 /= 1000000;
$lon2 /= 1000000;
// Actual calculations here.
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if ($unit == "K")
return ($miles * 1.609344);
else if ($unit == "N")
return ($miles * 0.8684);
else
return $miles;
}
// compare distances, helpful for sorting buildings
function _cmpDist($buildA, $buildB) {
if ($buildA->distance == $buildB->distance) {
return 0;
}
return ($buildA->distance < $buildB->distance) ? -1 : 1;
}
}
?>