Hi all
I have been working on a google map adding some markers, works ok. The problem now is, I need to display markers from a new json object with deeper nesting. Not sure how to do this?
My first instance which works, using just a couple of markers for viewing purposes:
// The JSON data
var data = [{
"title":"Arts",
"lat": 51.425966,
"lng": -0.564660},
{
"title":"Annexe",
"lat": 51.425923,
"lng": -0.562633}
];
// Looping through all the entries from the JSON data
for(var i = 0; i < data.length; i++) {
// Current object
var obj = data[i];
// Adding a new marker for the object
var marker = new google.maps.Marker({
position: new google.maps.LatLng(obj.lat,obj.lng),
map: map,
title: obj.title
});
}
Now with my new json object, I have deeper nesting, not sure how I should amend the loop so I can display the markers?
// The JSON data
var data = {
"markers": {
"buildings": [
{
"title":"Arts",
"lat": 51.425966,
"lng": -0.564660},
{
"title":"Annexe",
"lat": 51.425923,
"lng": -0.562633}
],
"places to eat": [
{
"title":"8bar",
"lat": 51.436741,
"lng": -0.563850},
{
"title":"Cafe",
"lat": 51.427635,
"lng": -0.563410}
],
"sport": [
{
"title":"Fitness",
"lat": 51.423456,
"lng": -0.559371},
{
"title":"Pitches and Courts",
"lat": 51.422538,
"lng": -0.558422}
]
}
}
My end goal will display each array of markers inside their own tab.
Any help thanks, Barry