1
Hello!
In my Javascript code I get the following error: "Uncaught Typeerror: Cannot read Property 'split' of Undefined". As I’m new in the area, I don’t quite understand how to solve the problem, someone can help me identify it?
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
var marks = [];
for (var i = 0; i < location.length; i++) {
marks[i] = createMark(i); /*ERRO*/
}
function createMark() {
var imagePath = "marker" + (i + 1) + ".png";
var image = imagePath;
var markers = [];
var lat = locations[i].split(',')[0]; /*ERRO*/
var long = locations[i].split(',')[1];
var location = new google.maps.LatLng(lat, long);
var marker = new google.maps.Marker({
position: location,
map: map,
icon: image
});
marker.setTitle("Cliente");
var textOrder = "<strong> Ponto: </strong> " + (i + 1) + ". <br> <strong> Latitude: </strong>" + lat + ", <strong> Longitude: </strong>" + long;
var infowindow = new google.maps.InfoWindow({
content: textOrder
});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
}
Forgot to give arguments to the function
function createMark()
... I think you want tofunction createMark(i)
. But there are more things, this function returns nothing, somarks[i]
will giveundefined
.– Sergio
I thank Sergio for the help! But previously this code worked, only now began to return me errors... If it’s not abuse on my part, would you tell me what kinds of arguments I should pass to Mark[i]?
– Z..
At the end of the joint function
return marker;
Thus the intância of the marker is stored, in the respectivemark[i]
.– Sergio
Sergio, thanks again! It still didn’t work... I will post the full code...
– Z..
Can you make a working example? (that shows the error and has HTML). I think you will need these 3 amendments: https://paste.ofcode.org/33TFGAbVx5D5EjsVapDMgqd
– Sergio
It worked perfectly Sergio!!! Thanks!!! -D
– Z..