-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmaps.php
115 lines (79 loc) · 2.39 KB
/
gmaps.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
require_once 'classes/GMaps.class.php';
require_once 'classes/DbConfig.class.php';
require_once 'DB/DataObject.php';
DbConfig::setup();
$action = $_POST['action'];
// if(!isset($action)) $action = $_GET['action'];
switch ($action) {
case "listCountries":
echo listCountries();
break;
case "listStates":
echo listStates();
break;
case "listAirports":
echo listAeroports();
break;
case "generateMap":
echo generateMapImage();
break;
default:
break;
}
function listCountries() {
$airplanes = DB_DataObject::factory("aeroports");
$airplanes->groupBy("ae_country");
$airplanes->orderBy("ae_country ASC");
$airplanes->find();
$countries = array();
while( $airplanes->fetch() ) {
$countries[] = $airplanes->ae_country;
}
// $countries = array("AR", "US", "LI");
return json_encode($countries);
}
function listStates() {
// DB_DataObject::debugLevel(5);
$country = $_POST['ae_country'];
$airplanes = DB_DataObject::factory("aeroports");
$airplanes->whereAdd("ae_country = '$country'");
$airplanes->groupBy("ae_state");
$airplanes->orderBy("ae_state ASC");
$airplanes->find();
$states = array();
while ( $airplanes->fetch() ) {
$states[] = $airplanes->ae_state;
}
// $states = array("CA", "FL", "MI", "MA", "NY", "WA");
return json_encode($states);
}
function listAeroports() {
$country = $_POST['ae_country'];
$state = $_POST['ae_state'];
$aeroports = DB_DataObject::factory("aeroports");
$aeroports->ae_state = $state;
$aeroports->ae_country = $country;
$aeroports->find();
$list = array();
while( $aeroports->fetch() ) {
$list[] = array("code" => $aeroports->ae_key, "name"=> $aeroports->ae_name ." (" . $aeroports->ae_key . ")");
}
// $list = array( array("code"=> "KJFK", "name" => "Kennedy International (KJFK)"), array("code" => "KLAX", "name" => "Los Angeles International (KLAX)"));
return json_encode($list);
}
function generateMapImage() {
// fetch the code IACI
$ae_key = $_POST['ae_key'];
$aeroport = DB_DataObject::factory("aeroports");
$aeroport->ae_key = $ae_key;
$aeroport->find(true);
// echo "" . $aeroport->ae_latitude . "," . $aeroport->ae_longitude . "";
$map = new GMaps();
$map->setZoom("12");
$map->setMarkers(array("" . $aeroport->ae_latitude . "," . $aeroport->ae_longitude . ""));
$map->setMapType("roadmap");
$map->setSize("640x480");
echo "<img src='" . $map->generateUrl() . "'>";
}
?>