So I'm using a .json file to feed marker information for my google maps script. For some reason, it will not render the map marker.
The map will render and I can place a marker as documented from google but when I try to convert my JSON data to render the marker it simply does nothing. No console errors either.
You'll note the console logs as I've been trying to figure this out and I end up with:
[0] Event Location: [object Object]
Am I not properly creating the object for this?
jQuery(document).ready(function ($) {
$.getJSON('../wp-content/plugins/loopden/json/map.json', function (eventsData) {
// Grabbing our JSON file to mark the map.
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
// Get the size of an object
var eventsSize = Object.size(eventsData);
console.log(eventsSize);
console.log(eventsData[0].lat);
for (var i = 0, l=eventsSize; i <l; i++){
var lat = eventsData[i].lat;
var lng = eventsData[i].lng;
var latlng = {"lat":parseInt(lat) , "lng":parseInt(lng)};
console.log('['+i+'] Event Location: '+latlng);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: eventsData[i].title
});
}
});
});
Here is the JSON data I'm working with:
{
"0": {
"lat": "-93.2745179",
"lng": "44.9817854",
"title": "Super Cool Event",
"date": "2017-08-25",
"time": "8:00pm - 10:00am",
"cost": "$15",
"bio": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec consectetur, leo ac gravida vestibulum, nisi metus posuere nibh, malesuada faucibus erat eros nec metus. Morbi tincidunt iaculis eros quis fringilla.",
"featured": "off"
}
}