I using a Google Maps Complex Markers example to put markers in some places from a Json request. But I received this message:
Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'beaches.length')
Isn't clear for me why the JSON not load. I am newbie in Javascript/JQuery, so I need help.
Originally, the variable beaches is feeded inside of initMap():
var beaches = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
I change to get these data using a loadJSON call outside of the iniMap() function.
var beaches;
function setup() {
loadJSON("getData.php", gotData, 'jsonp');
}
function gotData(data) {
beaches = data;
}
As you can see I used "jsonp" for security reasons. I try to clear it, but the issue continues.
To present data, this call is executed. The issue occurs in "beaches.lenght":
for (var i = 0; i < beaches.length; i++) {
var beach = beaches[i];
var marker = new google.maps.Marker({
position: {lat: beach[1], lng: beach[2]},
map: map,
shape: shape,
title: beach[0],
zIndex: beach[3]
});
}
I will gratefull for any help...