...

View Full Version : Array of objects question !



amol0010
08-22-2007, 10:11 PM
I have a question regarding Javascript object arrays -

Suppose I have a global variable which is an object array


//Global variable Point Of Interest
var PointsOfInterest = new Array('lat','lng');



I also have a table named markers in my MySQL database, the script phpsqlajax_genxml.php reads the database, outputs it into XML.



//-------------Read the markers/Points of interest from the database----------------

GDownloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");

for (var i = 0; i < markers.length; i++) {


PointsOfInterest[i] = (parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")) );


}
});


I want to be able to assign the object of "markers" to PointsOfInterest,

e.g. if

markers[o].lat = 56.4113 and markers[0].lng = -2.9145

then I should be able to assign,

PointsOfInterest[0] = markers[0];

and then later be able to call PointsOfInterest[0].lat and PointsOfInterest[0].lng so that they return values 56.4113 and -2.9145 respectively

Any idea on how to do this ?


Thanks,
Amol

mcjwb
08-23-2007, 09:06 AM
I want to be able to assign the object of "markers" to PointsOfInterest,

e.g. if

markers[o].lat = 56.4113 and markers[0].lng = -2.9145

then I should be able to assign,

PointsOfInterest[0] = markers[0];

and then later be able to call PointsOfInterest[0].lat and PointsOfInterest[0].lng so that they return values 56.4113 and -2.9145 respectively

markers[0] will be an xml element, so while you can assign markers[0] to PointsOfInterest[0] you would have to access the lat and long attributes via the getAttribute("lat") method.

Did my answer to your older post (http://www.codingforums.com/showthread.php?t=121554) not help? Do you need a further explanation?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum