I made an application that takes the map coordinates and shows them on the map. I'm getting coordinates (in lng and lat) from a file with a Json extension. I assigned the relevant key values to the row in the row (called markers). but the problem is this: I want to do this with the help of the for loop and I want to put the relevant keys in the index. so when I open the program I do not want to manually assign the markers' items according to the number of information in the .json extension file. I want to read information from .json file and assign values to the keys (by loop) in the markers' directory. Could you help me with this problem?
<script type="text/javascript" src="data.json"></script>
<script type="text/javascript">
var mydata = JSON.parse(data);
var markers = [
{
"title": mydata[0].yer,
"lat": mydata[0].lat,
"lng": mydata[0].lng,
}
,
{
"title": mydata[1].yer,
"lat": mydata[1].lat,
"lng": mydata[1].lng,
}
,
{
"title": mydata[2].yer,
"lat": mydata[2].lat,
"lng": mydata[2].lng,
}];
my json file:
data = '[{"yer" : "Besiktas", "lat" : "41.044161", "lng" : "29.001056"},{"yer" : "Eminönü", "lat" : "41.017513", "lng" : "28.970939"},{"yer" : "Zeytinburnu", "lat" : "40.990828", "lng" : "28.895325"}, {"yer" : "Aydın Üniv.", "lat" : "40.995836", "lng" : "28.797562"}]';