This seems to be describing the same code I'm using, but I can't
figure it out. This is what I'm running (apologies I can't show a
page, it's all locked down on company servers...):


function usePointFromPostcode(postcode, callbackFunction, text) {

        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);
                                callbackFunction(point, text);
                        }else{
                                alert("Postcode not found!");
                        }
                });

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

function createMarker(point, text) {
  var marker = new GMarker(point, baseIcon);
  map.setCenter(point, 12);
  map.addOverlay(marker);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml("<b>" + text + "</b>");
  });
return marker;

}

The rest of my script loads the map etc.

On my webpage, I call the function like this:

                <script type="text/javascript">
                function doStuff()
                {

                        var myPostCode = 'HG1 2RT';
                        var text = 'Hello';
                        usePointFromPostcode(myPostCode, createMarker, text);

                        var myPostCode = 'HG1 4RT';
                        var text = 'Goodbye';
                        usePointFromPostcode(myPostCode, createMarker, text);


                }
                addLoadEvent(doStuff);
                </script>

This results in two markers, correctly placed, both with the text
'Goodbye'. How can I fix this?

Thanks
Matt

On Dec 26 2008, 3:17 am, "[email protected]" <[email protected]>
wrote:
> On Dec 24, 9:13 am, "[email protected]" <[email protected]>
> wrote:
>
> > On Dec 24, 8:49 am, Tim <[email protected]> wrote:
>
> > > I've got an odd issue that I just can't spot on this 
> > > page:http://nhsht.thesitedoctor.co.uk/schools-and-training.aspx
>
> > > For some reason, the same infoWindow is show for each point and I've
> > > not unrolled any of the functions as far as I'm aware.
>
> > > I'm sure it's something obvious, can you spot it?
>
> > The map doesn't show any markers at all in FF.  The error console
> > reports the following 2 errors:
> > =============================================
> > Error: illegal character
> > Source File:http://nhsht.thesitedoctor.co.uk/schools-and-training.aspx
> > Line: 119
> > Source Code:
> > ‘UA-6784143-1’, // Your GA tracker code
> > =============================================
> > Error: map is undefined
> > Source File:http://nhsht.thesitedoctor.co.uk/scripts/gmap.js
> > Line: 36
> > =============================================
>
> > I do see the behavior you describe in IE7.  All the markers have the
> > contents of the _last_ marker.
>
> > Observation: You are geocoding your markers everytime you load the
> > page and running multiple geocodes in parallel.  That is bad practice
> > (unless the markers will move).  Try geocoding them once then using
> > the coordinates in your page.  See this page from Mike Williams'
> > tutorial for more information:
> > Part 17 Geocoding multiple addresses
>
> http://econym.org.uk/gmap/geomulti.htm
>
>
>
> In playing with it, it looks like it is geocoding the multiple points
> OK (using the localSearch object).  The issue is that there is only
> one call back function for the localSearch object and it returns the
> its results asynchronously.  By the time the results are returned, the
> callback function has been set to its value by the last
> usePointFromPostcode call, so all the results use the values set by
> that last call.
>
>   -- Larry

--~--~---------~--~----~------------~-------~--~----~
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