-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopenkis_API.php
executable file
·97 lines (93 loc) · 2.53 KB
/
openkis_API.php
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
<?php
/**
* @package Flatnux
* @author Alessandro Vernassa <[email protected]>
* @copyright Copyright (c) 2011
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License
*/
//ob_start();
global $_FN;
require_once "include/flatnux.php";
require_once "modules/dbview/FNDBVIEW.php";
$op=FN_GetParam("op",$_REQUEST);
switch($op)
{
case "near":
GetNear();
break;
default:
$config=FN_LoadConfig("modules/dbview/config.php",$_FN['mod']);
$dbview=new FNDBVIEW($config);
$table=FN_XmlTable($config['tables']);
$params=$_REQUEST;
if (empty($params['fields']))
{
$params['fields']="code,latitude,longitude,elevation";
$results=$dbview->GetResults($config,$params);
}
break;
}
dprint_r(count($results));
dprint_r($results);
/**
*
* @global type $_FN
*/
function GetNear()
{
global $_FN;
$mod=FN_GetParam("mod",$_REQUEST);
$params['fields']="code,latitude,longitude,elevation,name";
$config=FN_LoadConfig("modules/dbview/config.php",$mod);
$lat=FN_GetParam("lat",$_REQUEST);
$lon=FN_GetParam("lon",$_REQUEST);
$op=FN_GetParam("op",$_REQUEST);
$lat=floatval($lat);
$lon=floatval($lon);
$lat=str_replace(",",".",$lat);
$lon=str_replace(",",".",$lon);
$dbview=new FNDBVIEW($config);
$allinrange=$dbview->GetResults(false,$params);
$near=0;
$mindiff=-1;
foreach($allinrange as $item)
{
if (!empty($item['latitude']))
{
$lat_=str_replace(",",".",$item['latitude']);
$lon_=str_replace(",",".",$item['longitude']);
$diff=calcola_distanza($lat,$lon,$lat_,$lon_);
if ($mindiff < 0 || $mindiff > $diff)
{
$mindiff=$diff;
$near=$item;
}
}
}
$ret ['methers']=round($mindiff,2);
$ret ['cave']=$near;
echo json_encode($ret);
die();
}
/**
*
* @param type $latitude1
* @param type $longitude1
* @param type $latitude2
* @param type $longitude2
* @return type
*/
function calcola_distanza($latitude1,$longitude1,$latitude2,$longitude2)
{
$theta=$longitude1 - $longitude2;
$miles=(sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
$miles=acos($miles);
$miles=rad2deg($miles);
$miles=$miles * 60 * 1.1515;
$feet=$miles * 5280;
$yards=$feet / 3;
$kilometers=$miles * 1.609344;
$meters=$kilometers * 1000;
return $meters;
}
?>