Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2007
    Posts
    61
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Array of objects question !

    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

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    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 not help? Do you need a further explanation?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •