I am trying to iterate through a JSON file and put relevant data inside my markers variable. through each iteration markers should change, however I am stuck. Does anyone know how to do this or how I could?
This is a smaller version of my JSON:
{"properties":
[{"latitude":"53.542637347578406","longitude":"-113.51709427725768",
"account":"1061985","value":"$500"},
{"latitude":"53.5384925504052","longitude":"-113.520385218556",
"account":"1248558","value":"$500"}]}
This is my JavaScript Code:
/* global fetch */
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
mapId: "8e0a97af9386fef",
center: {lat: 53.55204130841203, lng: -113.49684664653883},
zoom: 11,
mapTypeControl: false,
});
let myRequest = new Request("./src/mapview/properties.json");
fetch(myRequest)
.then(function(resp){
return resp.json();
})
.then(function(data) {
console.log(data.account);
});
const markers = [
[
"Assessed",
53.432556261744296,
-113.61359034412152,
"house-svgrepo-com.svg",
40,
41
]
];
for (let i = 0; i < markers.length; i++) {
const currMarker = markers[i];
const marker = new google.maps.Marker({
position: {lat: currMarker[1], lng: currMarker[2]},
map,
title: currMarker[0],
icon: {
url: currMarker[3],
scaledSize: new google.maps.Size(currMarker[4], currMarker[5])
},
// animation: google.maps.Animation.DROP
});
}
}
This is the HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edmonton Property Assessments</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Map View</h1>
<div id="map"></div>
<script src="script.js"></script>
<script
async
src="https://maps.googleapis.com/maps/api/js?key=UR_KEY&callback=initMap">
</script>
</body>
</html>