Thank you for your replies! I was able to get it to work by doing
this:

First, I declared "var soils;" at the top of my document.
Then, in my initialize function, I gave soils a value before I put my
event listener:

    soils = new google.maps.KmlLayer(null);
    google.maps.event.addListener(map, 'idle', showSoils);

Finally, I used setMap(null) at the beginning of my function to remove
whatever the current soils overlay was. Now it works!

New form of my function:

function showSoils() {

    //remove previous overlay
    soils.setMap(null);

    var zoomlevel = map.getZoom();

    //if the zoom level is close enough
    if(zoomlevel>13)
    {
            //obtain points in database-friendly format:
            var bounds = map.getBounds();
            var ne = String(bounds.getNorthEast());
            var firstcomma = ne.search("[,]");
            firstlat = ne.substring(1, firstcomma);
            firstlong = ne.substring(firstcomma+2, ne.length-1);

            var sw = String(bounds.getSouthWest());
            var firstcomma = sw.search("[,]");
            secondlat = sw.substring(1, firstcomma);
            secondlong = sw.substring(firstcomma+2, sw.length-1);

            bcoords = firstlat + " " + firstlong + ", " + secondlat +
" " + firstlong + ", " + secondlat + " " + secondlong + ", " +
firstlat + " " + secondlong + ", " + firstlat + " " + firstlong;

            var soils =  new google.maps.KmlLayer('http://myfarms.org/
test/soils_in_view.php?bcoords=' + escape(bcoords), { map: map,
preserveViewport: true });
    }
  }


Hopefully this will be helpful to someone else with the same question.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" 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-js-api-v3?hl=en.

Reply via email to