I am facing an issue with my json structure where I am unable to access certain properties. I can only access the main properties like type
, properties
, and so on within that hierarchy level. However, I cannot seem to access icon
, iconURL
, or title
. The data is present but I can't access them individually.
When I try to retrieve just the title using
console.log(markerRE[i].properties)
, it displays all the properties perfectly. But when I specifically request the title, it throws an error saying can't read property properties of undefined
.
var markerRE = [{}]; //JSON ARRAY
$.ajax({
url: 'consulta4.php',
data: {},
method: 'POST',
dataType: 'json',
success: function (data) {
for (var i = 0; i < Object.keys(data).length; i++) {
markerRE.push({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [data[i].longitude, data[i].latitude]
},
"properties": {
"title": "Emergency: " + data[i].priority,
"id": data[i].id_emergency,
//"description":"<button class='RE'>oisdjos</button>", Alternative way to add html
"icon": {
"iconUrl": data[i].imagen,
"iconSize": [50, 50], // size of the icon
"iconAnchor": [25, 50], // point of the icon which will correspond to marker's location
"popupAnchor": [0, -25], // point from which the popup should open relative to the iconAnchor
"className": "dot"
}
}
}
);
console.log(markerRE[i].properties.title);
}
}
});