I'm currently working on a project that involves utilizing a JSON data structure like the one shown below:
[
{
"lat": 53.1522756706757,
"lon": -0.487157731632087,
"size": 63,
"field": "TestField",
"variety": "TestVariety",
"count": 1
}
]
This JSON will contain additional entries with different locations and count values. However, I am encountering an error titled above when implementing the following code.
let map;
let testField = new google.maps.LatLng(53.150, -0.488);
let options = {
zoom: 6,
center: testField,
mapTypeId: 'satellite',
};
function createMap(data) {
let mapElement = document.getElementById('map');
let geometry, weighted, count, heatData;
let heatmap, points;
map = new google.maps.Map(mapElement, options);
heatData = [];
for (var i = 0; i < data.length; i++) {
geometry = data[i];
weighted = {};
count = data[i].count;
weighted.location = new google.maps.LatLng(
data.lat,
data.lon);
weighted.weight = count
heatData.push(weighted);
}
points = new google.maps.MVCArray(heatData);
console.log(data);
heatmap = new google.maps.visualization.HeatmapLayer({
data: points,
opacity: 0.9,
radius: 20
});
heatmap.setMap(map);
}
$(function () {
$.ajax({
type: "GET",
url: "field_example.json",
dataType: "json",
success: createMap
});
});
It seems like there is a concept that eludes me in this process, and any assistance would be greatly appreciated.