Google Maps API Newbie

Giganews Newsgroups
Subject: Google Maps API Newbie
Posted by:  Mojo (please@dont.spam.com)
Date: Mon, 4 Jul 2011

Hi All

Wondered if you could help.

I've copied a brilliant piece of code from somebody called Tom to enable me
to throw postcodes at the Google Maps API and add markers to a map.  The
reason I need this is that I've got a number of post codes and I want to
show them where they are in the UK.

The markers work fine, but when I try and add text (through a mouseover
bubble) for each marker the API makes the last entry the text for all of the
markers.  For example, if the last text var is Bristol then all markers (10,
15, 50, etc) will show Bristol rather than London, Cardiff, etc.

Code is currently as follows:

<<<<<<<<<<<<<< below is in the header

function usePointFromPostcode(postcode, school) {

//alert(school);

localSearch.setSearchCompleteCallback(null,
  function() {

  if (localSearch.results[0])
  {
    var resultLat = localSearch.results[0].lat;
    var resultLng = localSearch.results[0].lng;
    var point = new GLatLng(resultLat,resultLng);
      var marker = new GMarker(point,iconRed);
        GEvent.addListener(marker, "mouseover", function() {
        marker.openInfoWindowHtml(school);
        });
        map.addOverlay(marker);
        marker == '';
  }else{
    alert("Postcode not found!");
  }
  });

localSearch.execute(postcode + ", UK");
}

<<<<<<<<<<<< below is in the BODY

<script type="text/javascript">
usePointFromPostcode('S1 5PA', 'Sheffiled');
usePointFromPostcode('S3 4DT', 'Worksop');
</script>

<div id="map"></div>

Can anybody see where I'm going wrong??

Thanks

Replies