da ich eine Routenplanung mit Google für Contenido benötigt habe, möchte ich euch diese zur Verfügung stellen.
Vielleich kann es ja jemand von euch brauchen.
Die Konfiguration sollte selbsterklärend sein.
Zur Installation:
Im body-Tag eures Layouts müsst ihr folgende Erweiterung einfügen.
Code: Alles auswählen
<body onLoad="if(useOnLoad==true){load();}">
Im Output-Modul am Ende wird diese JS-Variable auf true gesetzt.
INPUT:
Code: Alles auswählen
?><?php
/***********************************************
* CONTENIDO MODUL - INPUT
*
* Modulname : GoogleRoutenplanung
* Author(s) : Matthias Roth
* Created : 02.11.2007
************************************************/
// ### new settings
$mapAPIkey = "CMS_VALUE[1]";
$mapHead = "CMS_VALUE[2]"; // Ueberschrift der Karte
$mapWidth = "CMS_VALUE[3]"; // Breite der Karte
$mapHeight = "CMS_VALUE[4]"; // Hoehe der Karte
$mapType = "CMS_VALUE[14]"; // Art (Karte, Satellit, Hybrid)
$routeHead = "CMS_VALUE[5]"; // Ueberschrift der Routenplanung
$routeFrom = "CMS_VALUE[6]"; // Startadresse der Routenplanung
$routeTo = "CMS_VALUE[7]"; // Zieladresse der Routenplanung
$displayHead = "CMS_VALUE[8]"; // Ueberschrift der Anfahrtsbeschreibung
$displayWidth = "CMS_VALUE[9]"; // Breite der Anfahrtsbeschreibung
$defaultLat = "CMS_VALUE[10]"; // Mittelpunkt der Zieladresse (Laengengrad)
$defaultLon = "CMS_VALUE[11]"; // Mittelpunkt der Zieladresse (Breiengrad)
$defaultHeight = "CMS_VALUE[12]"; // Sichthoehe der Zieladresse
$defaultMarker = "CMS_VALUE[15]"; // Marker bei Start geoeffnet
$defaultText = "CMS_VALUE[13]"; // Text des Markers
( $defaultMarker == "on" )? $defaultMarkerChecked = " checked " : $defaultMarkerChecked = "";
echo '
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("GoogleMaps API Key:").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[1]" value="'.$mapAPIkey.'" style="width:400px"></td>
</tr>
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("Überschrift Kart (optional):").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[2]" value="'.$mapHead.'" style="width:200px"></td>
</tr>
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("Breite der Karte in px:").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[3]" value="'.$mapWidth.'" style="width:50px;text-align:right;">px</td>
</tr>
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("Höhe der Karte in px:").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[4]" value="'.$mapHeight.'" style="width:50px;text-align:right;">px</td>
</tr>
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("Kartentyp:").'</td>
<td class="text_medium" style="padding:5px">
<select name="CMS_VAR[14]">
<option value="G_NORMAL_MAP">Karte</option>
<option value="G_SATELLITE_MAP">Satellit</option>
<option value="G_HYBRID_MAP">Hybrid</option>
</select>
</td>
</tr>
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("Überschrift Eingabefeld (optional):").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[5]" value="'.$routeHead.'" style="width:200px"></td>
</tr>
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("Startadresse der Routenplanung (optional):").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[6]" value="'.$routeFrom.'" style="width:300px"></td>
</tr>
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("Zieladresse der Routenplanung:").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[7]" value="'.$routeTo.'" style="width:300px"></td>
</tr>
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("Überschrift Ausgabe (optional):").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[8]" value="'.$displayHead.'" style="width:200px"></td>
</tr>
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("Breite der Ausgabe in px:").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[9]" value="'.$displayWidth.'" style="width:50px;text-align:right;">px</td>
</tr>
<tr>
<td colspan="2" class="text_medium" style="padding:5px">'.mi18n("Default Zieladresse:").'</td>
</tr><tr>
<td class="text_medium" style="padding:5px">'.mi18n("Breitengrad:").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[10]" value="'.$defaultLat.'" style="width:100px"> [49.598133]</td>
</tr>
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("Längengrad:").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[11]" value="'.$defaultLon.'" style="width:100px"> [11.003443]</td>
</tr>
<tr>
<td class="text_medium" style="padding:5px">'.mi18n("Betrachtungshöhe:").'</td>
<td class="text_medium" style="padding:5px"><input type="text" name="CMS_VAR[12]" value="'.$defaultHeight.'" style="width:50px"> [15]</td>
</tr>
<tr>
<td valign="top" class="text_medium" style="padding:5px">'.mi18n("Marker öffnen:").'</td>
<td class="text_medium" style="padding:5px"><input type="checkbox"'.$defaultMarkerChecked.' name="CMS_VAR[15]"></td>
</tr>
<tr>
<td valign="top" class="text_medium" style="padding:5px">'.mi18n("Text für Marker (optional):").'</td>
<td class="text_medium" style="padding:5px"><textarea style="width:400px;height:150px;" name="CMS_VAR[13]">'.$defaultText.'</textarea></td>
</tr>
';
echo '</table>';
?><?php
OUTPUT:
Code: Alles auswählen
<?php
/***********************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname : GoogleRoutenplanung
* Author(s) : Matthias Roth
* Created : 02.11.2007
************************************************/
// ### import settings
$mapAPIkey = "CMS_VALUE[1]";
$mapHead = "CMS_VALUE[2]";
$mapWidth = "CMS_VALUE[3]";
$mapHeight = "CMS_VALUE[4]";
$mapType = "CMS_VALUE[14]";
$routeHead = "CMS_VALUE[5]";
$routeFrom = "CMS_VALUE[6]";
$routeTo = "CMS_VALUE[7]";
$displayHead = "CMS_VALUE[8]";
$displayWidth = "CMS_VALUE[9]";
$defaultLat = "CMS_VALUE[10]";
$defaultLon = "CMS_VALUE[11]";
$defaultHeight = "CMS_VALUE[12]";
$defaultMarker = "CMS_VALUE[15]";
$defaultText = "CMS_VALUE[13]";
$defaultTextHTML = ereg_replace("(\r\n|\n|\r)", "<br />", $defaultText);
$defaultTextNorm = ereg_replace("(\r\n|\n|\r)", "\\n", $defaultText);
/***********************************************
Weitere Einstellung der Anzeige können direkt im Script vorgenommen werden.
Die Komplette API von GoogleMaps steht unter:
http://www.google.com/apis/maps/documentation/
***********************************************/
?>
<script src=" http://maps.google.com/?file=api&v=2.x&key=<?=$mapAPIkey;?>"
type="text/javascript"></script>
<br/>
<b><?=$mapHead;?></b><br />
<div id="map_canvas" style="width: <?=$mapWidth;?>px; height: <?=$mapHeight;?>px"></div>
<form action="#" name="googleRouteFrm" onSubmit="setDirections(document.googleRouteFrm.from.value, document.googleRouteFrm.to.value, document.googleRouteFrm.locale.value); return false;">
<br /><b><?=$routeHead;?></b><br />
<table>
<tr>
<td>Start:<br /> </td>
<td><input type="text" size="30" id="fromAddress" name="from" value="<?=$routeFrom;?>"/><br />
Format: PLZ Ort, Strasse Nummer</td>
</tr>
<tr>
<td>Ziel:</td>
<td>
<input type="hidden" size="25" id="toAddress" name="to" value="<?=$routeTo;?>" />
<?=$routeTo;?>
</td>
</tr>
<tr>
<td><input type="hidden" name="locale" value="de" /> <!-- DE als Standard setzen --></td>
<td><input name="submit" type="submit" value="Anfahrt berechnen" /></td>
</tr>
</table>
</form>
<br /><b><?=$displayHead;?></b><br />
<div id="directions" style="width: <?=$displayWidth;?>px">Für die Routenberechnung geben Sie bitte eine Startadresse an.</div>
<script type="text/javascript">
var map;
var gdir;
var geocoder = null;
var addressMarker;
var html = '<?=($defaultTextHTML);?>';
// Funktion zum Erstellen des Markers und Icons
function createMarker(point, icon) {
var marker = new GMarker(point, icon);
// Show this marker's index in the info window when it is clicked.
GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); });
return marker;
}
function load() { // wenn geladen, dann default-Werte zeigen
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas")); // Karte initialisieren
map.addControl(new GMapTypeControl()); // Karte, Satelit, Hybrid anzeigen
map.addControl(new GSmallZoomControl()); // Zoom-Felder anzeigen
gdir = new GDirections(map, document.getElementById("directions"));
// GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
// Kartenausschnitt erstellen und anzeigen
map.setCenter(new GLatLng(<?=$defaultLat;?>, <?=$defaultLon;?>), <?=$defaultHeight;?>, <?=$mapType;?>);
// Bild, Schatten und Groesse fuer Icon erstellen
var icon = new GIcon();
icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
icon.iconSize = new GSize(12, 20);
icon.shadowSize = new GSize(22, 20);
icon.iconAnchor = new GPoint(6, 20);
icon.infoWindowAnchor = new GPoint(5, 1);
// Icon und Marker setzen
var point2 = new GLatLng(<?=$defaultLat;?>, <?=$defaultLon;?>);
var marker = createMarker(point2, icon);
map.addOverlay(marker);
<?php if($defaultMarker == "on") :
echo '
map.openInfoWindowHtml(map.getCenter(), (html));
';
endif;
?>
// alernativ kann hier gleich eine Route berechnet werden
//setDirections("Startpunkt", "Endpunkt", "de_DE");
}
}
// Route berechnen und anzeigen
function setDirections(fromAddress, toAddress, locale) {
gdir.load("from: " + fromAddress + " to: " + toAddress,
{ "locale": locale });
}
// Fehlerbehandlung, wenn nötig
function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
alert("Die Adresse konnte nicht berechent werden.\nMöglicher Grund ist, dass die Adresse sehr neu oder fehlerhaft ist.\nError code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
alert("Die Adresse konnte nicht berechnet werden. Ein Grund ist nicht bekannt.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
alert("Der HTTP q-Wert fehlt oder hat keinen Inhalt. \nMögliche Ursache: Es wurde keine Adresse eingegeben.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_KEY)
alert("Der interne Key ist nicht gültig oder fehlerhaft. \n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
alert("Der Anfahrtsplan konnte nicht berechnet werden.\n Error code: " + gdir.getStatus().code);
else alert("Es ist ein unbekannter Fehler aufgetreten.");
}
// setzen der onLoad-Function im Bodytag.
useOnLoad = true;
</script>