PlanetGMaps Forum

planetGMaps

Die deutsche Google Maps Community.
Die Möglichkeiten sind da!

Forum

Forum Suche | Forum Übersicht | Anmerkung: registrierte Benutzer können sich über neue Einträge benachrichtigen lassen | Anmerkung: registrierte Benutzer können sich über neue Einträge benachrichtigen lassen


zum vorhergehenden Thema Thema drucken zum nächsten Thema

Übersicht ::  Google Maps API ::  JavaScript ::  Formular zur auswahl einer Adresse funktioniert nicht!
moderiert von: Steffen

Zum aktuellsten Beitrag 

Formular zur auswahl einer Adresse funktioniert nicht!

Aristico verfasst: 11.07.2008, 18:00
Neu hier
Neu hier
Aristico

registriert: Mai. 2008
Beiträge: 5

Status: offline
letzter Besuch: 15.07.08
Hallo,

ich habe folgendes Problem. Ich habe nicht wirklich Ahnung von Java Script und habe bin dabei eine Map zu erstellen die, das ist zumindestens der erste schritt, den nächsten Punkt aus einem Array bestimmt. Die Adresse zu diesem nächsten Punkt soll per Formular eingegeben werden. Eigentlich hat das Formular immer gut funktioniert, nur aus irgenteinem Grund will es nicht mehr.

Könnt Ihr Euch das mal anschauen? http://www.ohning.net

Es wäre klasse wenn Ihr mir helfen könnten.

Vielen Dank
Christian
Nach oben  Profil PM senden
 
Aristico verfasst: 15.07.2008, 10:57
Neu hier
Neu hier
Aristico

registriert: Mai. 2008
Beiträge: 5

Status: offline
letzter Besuch: 15.07.08
Hallo,

ich habe schon einen Fehler gefunden. Es stand was im Quellcode, was nicht da hin gehörte, das hat aber leider nicht zum gewünschten erfolg geführt.

Die Seite reagiert dann zwar auf den Klick beim Formular, aber es scheint die funktion "ok" nicht durchgeführt zu werden.

Für die Bessere Lesbarkeit habe ich das Array ein wenig gekürzt.

Ich hoffe Ihr könnt mir jetzt helfen!

Vielen Dank und Grüße schonmal im Vorraus
Christian

Der Bereinigte Quellcode:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtm...html1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Google Maps Example</title>









var map = null;
var geocoder = null;



function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}

// Achtung: Form Name muss hier 'Form1' sein

function ok()
{
var error="Bitte folgende Felder ausfüllen:\n\n";
checkKontakt = true;

// Strasse und Ort pruefen
if(document.Form1.strasse.value == "") {checkKontakt = false; var error=error + "Strasse\n";}

// Ist ein Eingabefehler aufgetaucht, so werden die errors ausgegeben
if(checkKontakt == false)
{
alert(error);
return false;
} else {
showAddress(document.Form1.strasse.value+', '+document.Form1.land.options[document.Form1.land.selectedIndex].value);
}
}



// Create an array containing objects with two attributes, name and location. These objects represent Geldautomaten.
var GAs = [

{"name": "010 - Geschäftsstelle Stellingen,Koppelstr. 2, 22527 Hamburg","location": new GLatLng(53.592702, 9.934254)},
{"name": "890 - Geschäftsstelle Poppenbüttel,Harksheider Str. 1, 22399 Hamburg","location": new GLatLng(53.659564, 10.084808)}

];


function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(53.54790652864021,10.02303957939148), 11);

// When the user clicks on the map, call the mapClick function.
GEvent.addListener(map, 'click', mapClick);

// Create and display markers for all Geldautomaten.
for (var i = 0; i < GAs.length; i++) {
aGA = GAs[i];
var GAmarker = createMarker(aGA["location"], aGA["name"]);
map.addOverlay(GAmarker);
}
}
}

// Creates and returns a marker at the given point. Sets up an event listener to show the given name when the marker is clicked.
function createMarker(point, title) {
var marker = new GMarker(point,{title:title});
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(title + '
Lat: ' + point.y + '
Lon: ' + point.x);
});
return marker;
}

// Called when the user clicks on the map. Computes the nearest Geldautomat to the clicked location, and displays its name and location below the map.
function mapClick(marker, latLngClicked) {
// Find the object on the page in which we will display the information for the nearest Geldautomat.
nearestDiv = document.getElementById("nearest");

// nearestGA contains the Geldautomat for which we currently think it's the nearest.
// First, just set it to the first Geldautomat in our array GAs.
// Then loop over the remaining Geldautomaten, each time checking if the distance between one of them is smaller then to the Geldautomat saved in nearestGA.
var nearestGA = GAs[0];
for (var i = 1; i < GAs.length; i++) {
aGA = GAs[i];
if (latLngClicked.distanceFrom(aGA["location"]) < latLngClicked.distanceFrom(nearestGA["location"])) {
nearestGA = aGA;
}
}

// Put the information for the nearest Geldautomat inside the reserved div.
nearestDiv.innerHTML = "Name of nearest GA: " + nearestGA["name"] + " --- Location: " + nearestGA["location"].lat() + " - " + nearestGA["location"].lng();
}


</head>


<body onload="load()" onunload="GUnload()">






<form name="Form1" method="get" action="" onSubmit="return ok();">


Strasse mit Hausnummer + Ort <input type="text" name="strasse" />


Land
<select name="land">
<option value="Deutschland" selected="selected">Deutschland</option>
</select>


<input type="submit" name="send" value="Senden">
</form>



</body>

</html>




editiert von: Aristico, 14.07.2008, 22:06 Uhr
Nach oben  Profil PM senden
 


User online:

Diese Angaben basieren auf den Useraktivitäten der letzten 10 Minuten

^ Top | © 2006 planet-gmaps.de | css | xhtml