0

I'm trying to implement Googlemaps in my Page but i'm getting into some problems surly because I'm still new with webdev.

I've followed the google API tutorial on saving data to a database and created the appropriate functions in my .js file.

The code looks like this:

    function createMarker(location){

    if(poiMode && activeMarkerIcon != null) {
        var marker = new google.maps.Marker({
        position: location,
        icon: activeMarkerIcon,
        clickable:true,
        draggable:true,
        animation:null,
        raiseOnDrag:false,
        title: Titel,
        map: map
        });
        useFilter();
    activeGroup.push(marker);  // Marker wird zum dazugehörigenArray hinzugefuegt
    map.setOptions({draggableCursor:'default'}) // Mauscursor wieder in ursprünglichen Zustand versetzen
    $('body, #poi1, #poi2, #poi3, #poi4, #poi5, #poi6, #poi7, #loeschen').removeClass('poi1A poi2A poi3A poi4A poi5A poi6A poi7A deleteA');
      var html = "<table>" +
      "<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>" +
      "<tr><td>Beschreibung:</td> <td><TEXTAREA id='description' rows='10' cols='50'></TEXTAREA></td> </tr>" +
      "<tr align='right'><td></td><td><input type='button' value='Speichern' onclick='saveData()'/></td> <td><input type='button' value='Abbrechen' onclick='infowindow.close()'/></td> </tr>";
      infowindow = new google.maps.InfoWindow({
          content: html
    });
    poiMode = false;
    infowindow.open(map, marker);
    google.maps.event.addListener(marker, 'click', function(event){
        clickOnMarker(marker);
    });
    $('.activeButton').removeClass("activeButton");

    }
}

and the saveData() function is in the same .js file and looks like this:

     function saveData() {
      var name = escape(document.getElementById("name").value);
      var address = escape(document.getElementById("address").value);
      var latlng = marker.getPosition();

      var url = base_url + "map/addMarker?name=" + name + "&address=" + address + "&description=" + "test" + "&user_id=" + "1" +"&lat=" + latlng.lat() + "&lng=" + latlng.lng() + "&date=" + "" +"&type=" + "poi";
      downloadUrl(url, function(data, responseCode) {
        if (responseCode == 200 && data.length <= 1) {
          infowindow.close();
          document.getElementById("message").innerHTML = "Location added.";
        }
      });
}

Yet when I press the save Button on my "Form" I get the console error:

Uncaught ReferenceError: saveData is not defined

Could you please tell me, what I'm doing wrong? since I cant see my own error. Thanks in Advance

4

1 回答 1

0

我通过定义saveData()为 infowindow 的函数解决了这个问题

infowindow.saveData = function(){
...
});

并使用以下方法调用该函数:

<input type='button' value='Save' onclick='infowindow.saveData()'/>

感谢巴西利库姆和其他所有人!

于 2013-05-25T14:18:27.180 回答