diff --git a/assets/imgs/custmarker.png b/assets/imgs/custmarker.png new file mode 100644 index 0000000..363da85 Binary files /dev/null and b/assets/imgs/custmarker.png differ diff --git a/mod_taxi.php b/mod_taxi.php new file mode 100644 index 0000000..f6af67b --- /dev/null +++ b/mod_taxi.php @@ -0,0 +1,271 @@ +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 = '
'+ + '

First location

'+ + '
'+ + '

Coordinates: '+location1+'

'+ + '

Address: '+address1+'

'+ + '
'+ + '
'; + + var text2 = '
'+ + '

Second location

'+ + '
'+ + '

Coordinates: '+location2+'

'+ + '

Address: '+address2+'

'+ + '
'+ + '
'; + + 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 = \"
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 += '
Tempo approssimativo '+travelmode+': '+response.routes[0].legs[0].duration.text; + distance += '
Costo approssimativo in euro: '+price; + document.getElementById('distance_road').innerHTML = distance; + } else { + alert('error: ' + status); + } + }); + + var text1 = '
'+ + '

First location

'+ + '
'+ + '

Coordinates: '+location1+'

'+ + '

Address: '+address1+'

'+ + '
'+ + '
'; + + var text2 = '
'+ + '

Second location

'+ + '
'+ + '

Coordinates: '+location2+'

'+ + '

Address: '+address2+'

'+ + '
'+ + '
'; + + 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')); + diff --git a/mod_taxi.xml b/mod_taxi.xml new file mode 100644 index 0000000..1ed4811 --- /dev/null +++ b/mod_taxi.xml @@ -0,0 +1,23 @@ + + + +Taxi Calculator +September 2011 +Jecko Development +info@jeckodevelopment.com +http://www.jeckodevelopment.com +Copyright (C) 2011 Jecko Development. All rights reserved. +GNU General Public License version 2 or later; see LICENSE.txt +1.0 +Taxi Rate Calculator + + mod_taxi.php + mod_taxi.xml + tmpl + assets + + + + + + \ No newline at end of file diff --git a/tmpl/default.php b/tmpl/default.php new file mode 100644 index 0000000..06409e3 --- /dev/null +++ b/tmpl/default.php @@ -0,0 +1,42 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Calcola il costo del tuo taxi
 
Indirizzo di partenza:  
Indirizzo di arrivo:  
Mezzo: + +
 
+
+
+
+ +