forked from designermonkey/addresslocationfield
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.driver.php
More file actions
executable file
·125 lines (103 loc) · 3.41 KB
/
Copy pathextension.driver.php
File metadata and controls
executable file
·125 lines (103 loc) · 3.41 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
Class extension_addresslocationfield extends Extension{
public function uninstall()
{
Symphony::Database()->query("DROP TABLE `tbl_fields_addresslocation`");
}
public function update($previousVersion){
$addresslocation_entry_tables = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_addresslocation`");
if(version_compare($previousVersion, '1.2.1', '<')){
if(is_array($addresslocation_entry_tables) && !empty($addresslocation_entry_tables))
{
foreach($addresslocation_entry_tables as $field)
{
Symphony::Database()->query(sprintf(
"ALTER TABLE `tbl_entries_data_%d` ADD `result_data` blob",
$field
));
}
}
}
if(version_compare($previousVersion, '1.2.2', '<')){
if(is_array($addresslocation_entry_tables) && !empty($addresslocation_entry_tables))
{
foreach($addresslocation_entry_tables as $field)
{
Symphony::Database()->query(sprintf(
"ALTER TABLE `tbl_entries_data_%d` ADD `neighborhood` varchar(255), ADD `neighborhood_handle` varchar(255)",
$field
));
}
}
}
if(version_compare($previousVersion, '1.2.3', '<')){
if(is_array($addresslocation_entry_tables) && !empty($addresslocation_entry_tables))
{
foreach($addresslocation_entry_tables as $field)
{
Symphony::Database()->query(sprintf(
"ALTER TABLE `tbl_entries_data_%d` MODIFY COLUMN `result_data` blob",
$field
));
}
}
}
return true;
}
public function install()
{
return Symphony::Database()->query("CREATE TABLE `tbl_fields_addresslocation` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`street_label` varchar(80) NOT NULL,
`city_label` varchar(80) NOT NULL,
`region_label` varchar(80) NOT NULL,
`postal_code_label` varchar(80) NOT NULL,
`country_label` varchar(80) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `field_id` (`field_id`)
) TYPE=MyISAM");
}
/*
Modified from:
http://www.kevinbradwick.co.uk/developer/php/free-to-script-to-calculate-the-radius-of-a-coordinate-using-latitude-and-longitude
*/
public function geoRadius($lat, $lng, $rad, $kilometers=false)
{
$radius = ($kilometers) ? ($rad * 0.621371192) : $rad;
(float)$dpmLAT = 1 / 69.1703234283616;
// Latitude calculation
(float)$usrRLAT = $dpmLAT * $radius;
(float)$latMIN = $lat - $usrRLAT;
(float)$latMAX = $lat + $usrRLAT;
// Longitude calculation
(float)$mpdLON = 69.1703234283616 * cos($lat * (pi/180));
(float)$dpmLON = 1 / $mpdLON; // degrees per mile longintude
$usrRLON = $dpmLON * $radius;
$lonMIN = $lng - $usrRLON;
$lonMAX = $lng + $usrRLON;
return array("lonMIN" => $lonMIN, "lonMAX" => $lonMAX, "latMIN" => $latMIN, "latMAX" => $latMAX);
}
/*
Calculate distance between two lat/long pairs
*/
public function geoDistance($lat1, $lon1, $lat2, $lon2, $unit)
{
$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 = strtolower($unit);
$distance = 0;
if ($unit == "k") {
$distance = ($miles * 1.609344);
} else if ($unit == "n") {
$distance = ($miles * 0.8684);
} else {
$distance = $miles;
}
return round($distance, 1);
}
}
?>