Code:
function DataCollection()
{
var obj = this; //reference to the created instance of DataCollection
this.points = []; //or you could do: obj.points = []; here within the constructor code
this.load = function(filename)
{
$.get(filename, function(xml){
$(xml).find("marker").each(
function(){
var name = $(this).find('name').text();
var address = $(this).find('address').text();
var lat = $(this).find('lat').text();
var lng = $(this).find('lng').text();
var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
*** HERE...add point to a collection (may an array) as property inside DataCollection object
obj.points.push(point);
});
});
}
}
var dc = new DataCollection();
dc.load();
Or, more appropriately, use prototype methods rather than define object methods in the constructor:
Code:
function DataCollection() {
this.points = [];
}
DataCollection.prototype.load = function(filename){
var obj = this;
$.get(filename, function(xml){
$(xml).find("marker").each(
function(){
var name = $(this).find('name').text();
var address = $(this).find('address').text();
var lat = $(this).find('lat').text();
var lng = $(this).find('lng').text();
var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
*** HERE...add point to a collection (may an array) as property inside DataCollection object
obj.points.push(point);
});
});
};
var dc = new DataCollection();
dc.load();
Bookmarks