I’m working on a google map application and I want some markers to load from a db and display them on a map. So I created an array and defined an object like this.
function shop_data(name,latitude,longitude,type)
{
this.name=name;
this.latitude=latitude;
this.longitude=longitude;
this.type=type;
}
Then I added some data retrieved from an ajax request to an array of ‘shop_data’ objects. The array is defined as ‘all_shops’.
var i=0;
for(var o in data){
var name = data[o].name;
var type = data[o].type;
var lat = data[o].lat;
var lng = data[o].lng;
all_shops[i]=new shop_data(name,lat,lng,type);
i++
}
Then when i call ‘all_shops[i].name’, it gives me the name as it is. But when I call ‘all_shops[i].lat’ or ‘all_shops[i].lng’ it gives me ‘undefined’. I tried parsing the lat,lng too. Here lat, lng are double variables in MySQL database.
I can get the lat,lng values without a problem from the received ajax data by calling, just name,type,lat,lng. But things go wrong when i put them all in an array and , call them from the array. Any help would be appreciated. Thanks.
You should call your
latitudeorlongitudefromall_shops[i]notlatorlngas you have your
shop_datafunction definition like thisor if want to use
latorlngthen changeshop_datafunction definition like