-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_taxi.php
271 lines (219 loc) · 8.93 KB
/
mod_taxi.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
// no direct access
defined('_JEXEC') or die;
//require_once dirname(__FILE__).'/helper.php';
$costokm = $params->get('eurokm');
$document = & JFactory::getDocument();
$document->addScript('http://maps.google.com/maps/api/js?sensor=true');
$document->addScriptDeclaration("
var location1;
var location2;
var address1;
var address2;
var latlng;
var geocoder;
var map;
var line;
var infowindow1;
var infowindow2;
var distance;
function initialize(){
geocoder = new google.maps.Geocoder();
address1 = document.getElementById(\"address1\").value;
address2 = document.getElementById(\"address2\").value;
if (geocoder){
geocoder.geocode( { 'address': address1}, function(results, status){
if (status == google.maps.GeocoderStatus.OK){
location1 = results[0].geometry.location;
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
geocoder.geocode( { 'address': address2}, function(results, status){
if (status == google.maps.GeocoderStatus.OK){
location2 = results[0].geometry.location;
showMap();
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
}
function showMap(){
latlng = new google.maps.LatLng((location1.lat()+location2.lat())/2,(location1.lng()+location2.lng())/2);
var maptype = document.getElementById('maptype').value;
var typeId;
if (maptype == 'roadmap')
typeId = google.maps.MapTypeId.ROADMAP;
else if (maptype == 'hybrid')
typeId = google.maps.MapTypeId.HYBRID;
else if (maptype == 'satellite')
typeId = google.maps.MapTypeId.SATELLITE;
else if (maptype == 'terrain')
typeId = google.maps.MapTypeId.TERRAIN;
var mapOptions = {
zoom: 1,
center: latlng,
mapTypeId: typeId
};
map = new google.maps.Map(document.getElementById(\"map_canvas\"), mapOptions);
google.maps.event.addListener(map, 'maptypeid_changed', function() {
maptype = map.getMapTypeId();
document.getElementById('maptype').value = maptype;
});
var rabbit = new google.maps.MarkerImage('distance-finder-custom-marker-image.png');
var marker1 = new google.maps.Marker({
map: map,
position: location1,
title: 'First location',
icon: rabbit,
draggable: true
});
var marker2 = new google.maps.Marker({
map: map,
position: location2,
title: 'Second location',
icon: rabbit,
draggable: true
});
var text1 = '<div id=\"content\">'+
'<h1 id=\"firstHeading\">First location</h1>'+
'<div id=\"bodyContent\">'+
'<p>Coordinates: '+location1+'</p>'+
'<p>Address: '+address1+'</p>'+
'</div>'+
'</div>';
var text2 = '<div id=\"content\">'+
'<h1 id=\"firstHeading\">Second location</h1>'+
'<div id=\"bodyContent\">'+
'<p>Coordinates: '+location2+'</p>'+
'<p>Address: '+address2+'</p>'+
'</div>'+
'</div>';
infowindow1 = new google.maps.InfoWindow({
content: text1
});
infowindow2 = new google.maps.InfoWindow({
content: text2
});
google.maps.event.addListener(marker1, 'click', function() {
infowindow1.open(map,marker1);
});
google.maps.event.addListener(marker2, 'click', function() {
infowindow2.open(map,marker2);
});
google.maps.event.addListener(marker1, 'dragend', function() {
location1 = marker1.getPosition();
drawRoutes(location1, location2);
});
google.maps.event.addListener(marker2, 'dragend', function() {
location2 = marker2.getPosition();
drawRoutes(location1, location2);
});
directionsService = new google.maps.DirectionsService();
directionsDisplay = new google.maps.DirectionsRenderer({
suppressMarkers: true,
suppressInfoWindows: true
});
directionsDisplay.setMap(map);
drawRoutes(location1, location2);
}
function drawRoutes(location1, location2){
geocoder = new google.maps.Geocoder();
if (geocoder){
geocoder.geocode({'latLng': location1}, function(results, status){
if (status == google.maps.GeocoderStatus.OK){
if (results[0]){
address1 = results[0].formatted_address;
document.getElementById(\"address1\").value = address1;
}
} else {
alert(\"Geocoder failed due to: \" + status);
}
});
}
if (geocoder){
geocoder.geocode({'latLng': location2}, function(results, status){
if (status == google.maps.GeocoderStatus.OK){
if (results[0]){
address2 = results[0].formatted_address;
document.getElementById(\"address2\").value = address2;
continueShowRoute(location1, location2);
}
} else {
alert(\"Geocoder failed due to: \" + status);
}
});
}
}
function continueShowRoute(location1, location2){
if (line){
line.setMap(null);
}
line = new google.maps.Polyline({
map: map,
path: [location1, location2],
strokeWeight: 7,
strokeOpacity: 0.8,
strokeColor: '#FFAA00'
});
var R = 6371;
var dLat = toRad(location2.lat()-location1.lat());
var dLon = toRad(location2.lng()-location1.lng());
var dLat1 = toRad(location1.lat());
var dLat2 = toRad(location2.lat());
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(dLat1) * Math.cos(dLat1) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
document.getElementById(\"distance_direct\").innerHTML = \"<br/>Distanza tra i due punti (in linea d'aria): \"+d;
var travelmode = document.getElementById(\"travelMode\").value;
if (travelmode == \"driving\")
travel = google.maps.DirectionsTravelMode.DRIVING;
else if (travelmode == \"walking\")
travel = google.maps.DirectionsTravelMode.WALKING;
else if (travelmode == \"bicycling\")
travel = google.maps.DirectionsTravelMode.BICYCLING;
var request = {
origin:location1,
destination:location2,
travelMode: travel
};
directionsService.route(request, function(response, status){
if (status == google.maps.DirectionsStatus.OK){
var price = response.routes[0].legs[0].distance.value /1000 * $costokm + 5.0;
directionsDisplay.setDirections(response);
distance = 'Distanza tra i due punti scelti sul percorso: '+response.routes[0].legs[0].distance.text;
distance += '<br/>Tempo approssimativo '+travelmode+': '+response.routes[0].legs[0].duration.text;
distance += '<br/>Costo approssimativo in euro: '+price;
document.getElementById('distance_road').innerHTML = distance;
} else {
alert('error: ' + status);
}
});
var text1 = '<div id=\"content\">'+
'<h1 id=\"firstHeading\">First location</h1>'+
'<div id=\"bodyContent\">'+
'<p>Coordinates: '+location1+'</p>'+
'<p>Address: '+address1+'</p>'+
'</div>'+
'</div>';
var text2 = '<div id=\"content\">'+
'<h1 id=\"firstHeading\">Second location</h1>'+
'<div id=\"bodyContent\">'+
'<p>Coordinates: '+location2+'</p>'+
'<p>Address: '+address2+'</p>'+
'</div>'+
'</div>';
infowindow1.setContent(text1);
infowindow2.setContent(text2);
}
function toRad(deg){
return deg * Math.PI/180;
}
");
$document->addScriptDeclaration("
");
//$pflip = modPflipHelper::myfunction();
require JModuleHelper::getLayoutPath('mod_taxi', $params->get('layout', 'default'));