Thanks Andrew,
My peoblem to place label of county name on county boudries center.
all three county boudries place on map perfectly with for loop but
same time I need to find center of boudries nad want to place Label on
it.
If you add map.addOverlay(geoXml) in side callback
function ,everytime only one county boudry display.If you look at tmy
code you will notice that county is displaying correctly but problem
is with label.
var county=new Array(3);
county[0]="Adams_IL";
county[1]="Cook_IL";
county[2]="Lake_IL";
for(var i=0;i<county.length;i++){
var name=county[i].split("_");
var geoXml = new GGeoXml(""http://vconsign.net/
images/"+county[i]+".kml",function() {
if (geoXml.loadedCorrectly()) {
geoXml.gotoDefaultViewport(map);
var label = new ELabel(geoXml.getDefaultCenter(),name
[0], "style1");
map.addOverlay(label); }
});
map.addOverlay(geoXml);
}
I search lot on how to place lable on google map in center of boudries
and I found this solution which is grt for me but now its looks like
its not working with for loop.
On Feb 16, 11:26 am, "warden [Andrew Leach - Maps API Guru]"
<[email protected]> wrote:
> On Feb 16, 5:15 pm, NP <[email protected]> wrote:
>
> > Thanks Ross,
>
> > I understand this problem.
>
> Do you?
>
>
>
>
>
> > And wrote code like below.
>
> > var county=new Array(3);
> > county[0]="Adams_IL";
> > county[1]="Cook_IL";
> > county[2]="Lake_IL";
> > for(var i=0;i<county.length;i++){
> > var geoXml = new GGeoXml("http://vconsign.net/
> > images/"+county[i]+".kml");
> > alert(geoXml.loadedCorrectly());
> > alert(geoXml.getDefaultCenter());
> > map.addOverlay(geoXml);
> > }
>
> > Why alert(geoXml.loadedCorrectly()) return false and if
> > geoXml.getDefaultCenter() is null instead of lat,lng even geoxml
> > object loaded perfectly in google map?
>
> At the time the alert is run, geoXml has *not* loaded. It's loaded in
> the background as a separate thread. If you delay execution enough
> with your alerts, then by the time map.addOverlay() is reached, geoXml
> will contain a GGeoXml object because it will have come back from
> Google's servers by then.
>
> You *need* a callback function to handle what comes back.
>
> You may be able to get this to work by having a helper function to get
> closure on your variables, rather like Mike's "createMarker" function.
> Something like the following, perhaps (which is untested):
>
> function makeGeoXml(i) {
> var geoXml = new GGeoXml("http:...",
> function() {map.addOverlay(geoXml);});
> }
> for(var i=0;i<county.length;i++){
> makeGeoXml(i)
> }
>
> makeGeoXml is a helper function which keeps track of i and allows the
> GGeoXml's callback to add it to the map -- or do anything else you
> want. That helper function is called in the loop.
>
> Andrew- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---