0
I am now using other utilities of Google Maps Javascript API, I changed some parts of the code and he returned to have problems more or less in this same part where @Sergio helped me Link the question: Uncaught Typeerror: Cannot read Property 'split' of Undefined , follows the JS code:
JS:
var map = new google.maps.Map(document.getElementById("map"), mapOptions); // linha igual ao necessário
var marks = [];
for (var i = 0; i < location.length; i++) {
marks[i] = createMark(i); /*ERRO*/
}
function createMark(i) {
var imagePath = "marker" + (i + 1) + ".png";
var image = imagePath;
var markers = [];
if (!locations[i]) return null;
//inserindo nova parte da API
geocoder.geocode( {'address': location}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
resultsMap.setCenter(results[i].geometry.location);
var marker = new google.maps.Marker({
position: results[i].geometry.location,
map: map,
icon: image
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
}); //função inserida
marker.setTitle("Cliente"); /*ERRO*/
var textOrder = "<strong> Ponto: </strong> " + (i + 1);
var infowindow = new google.maps.InfoWindow({
content: textOrder
});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
geocodeAddress(geocoder, map); //linha inserida
});
return marker;
} }
ERROR RETURNED:
Uncaught ReferenceError: marker is not defined
at createMark (map_clients.js:67)
at mapCreate (map_clients.js:45)
Vlw ai personal!
within your createMark(i) Function you are setando Marker.setTitle('Client'), but you have not started the variable Marker... You should put var Marker = new google.maps.Marker(...) which is inside if outside the if scope or put the Marker.setTitle inside if
– Hugo Lima
@Hugo worked, thanks! Sorry for the impertinence, but I’m new to this and I don’t know how to deal with some mistakes... After doing what you said, he fixed those errors, but returned this "Invalidvalueerror: setPosition: not a Latlng or Latlngliteral: not an Object"
– Z..
No reason, we’re here to help... About your other error, you will have to create another question and also puts the location where you are trying this "setPosition", apparently you are trying to make a setPosition with an object other than: new google.maps.Latlng(lat,lng)
– Hugo Lima
OK @Hugo! Thanks for the help!
– Z..
If the Ugo answer solved this problem you should give the answer as accepted, to make it easier for other users who have the same problem. Welcome
– Miguel