Hello,

I have a problem with the api: i am trying to draw a polygone on the
map. To save it to the database, at each click, i am updating a hidden
textarea with the coordinates of that click.

The problem occurs when clicking inside the shape (if i put 5 points
that define a shape and the sixth inside the shape) the shape
dissapears and firebug shows me this error: a is undefined in
http://maps.gstatic.com/intl/en_ALL/mapfiles/250a/maps2.api/main.js.
If i click again on the map, the shape reappears, but everyclick from
that point on doesn't provide the script with the coordinates of the
point I clicked (polyPoints[i] is undefined in the code below).

Please help me with this.

The code:

if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(44.435251, 26.102829), 13);
    map.setUIToDefault();
    GEvent.addListener(map, "click", mapClick);
    geocoder = new GClientGeocoder();
}

// mapClick - Handles the event of a user clicking anywhere on the map
// Adds a new point to the map and draws either a new line from the
last point
// or a new polygon section depending on the drawing mode.
function mapClick(marker, clickedPoint) {
    polygonMode = true;

    // Push onto polypoints of existing polygon
    polyPoints.push(clickedPoint);
    drawCoordinates();
}

function drawCoordinates(){
    //Re-create Polyline/Polygon
    if (polygonMode) {
        polyShape = new
GPolygon(polyPoints,lineColor,lineWeight,opacity,fillColor,opacity);
    } else {
        polyShape = new
GPolyline(polyPoints,lineColor,lineWeight,opacity);
    }
    map.clearOverlays();

    // Grab last point of polyPoints to add marker
    marker = new GMarker(polyPoints[polyPoints.length -1]);
    map.addOverlay(marker);
    map.addOverlay(polyShape);
    logCoordinates();
}


function logCoordinates(){

    var header = "";

    // check mode
    if (polygonMode){
        header += "" + "";

        var footer = "";

        // print coords header
        document.getElementById("coords").value =  header;

        // loop to print coords
        for (var i = 0; i<(polyPoints.length); i++) {
            var lat = polyPoints[i].lat();
            var longi = polyPoints[i].lng();
            document.getElementById("coords").value += longi + ", " +
lat + " ;";
        }
    } else {
        alert('error in google maps /zone - invalid draw mode')
    }
    document.getElementById("coords").value +=  footer;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to