Reputation: 43
I am trying to add a custom marker from an array on Google Maps I have seen another question close to this but the code provided doesn't allow Google Maps API to pick the Marker Icon
function button1(location) {
var get1 = prompt ("Enter First Coord");
var get2 = prompt ("Enter Second Coord");
var icons = [
"https://raw.githubusercontent.com/Concept211/Google-Maps-Markers/master/images/marker_green.png",
"https://raw.githubusercontent.com/Concept211/Google-Maps-Markers/master/images/marker_purple.png",
"https://raw.githubusercontent.com/Concept211/Google-Maps-Markers/master/images/marker_orange.png",
"https://raw.githubusercontent.com/Concept211/Google-Maps-Markers/master/images/marker_white.png",
"https://raw.githubusercontent.com/Concept211/Google-Maps-Markers/master/images/marker_black.png",
"https://raw.githubusercontent.com/Concept211/Google-Maps-Markers/master/images/marker_blue.png"
];
var items;
var center = new google.maps.LatLng(get1,get2);
map.panTo(center);
var marker = new google.maps.Marker({
position: center,
map: map,
icon: items[Math.floor(Math.random()*icons .length)]
});
I keep getting a "items is not defined". If I define it above the code I get a different error saying "Cannot read property '3' of undefined" on the icon: items[Math.floor(Math.random()*icons .length)] code
If anyone knows the solution I would very much appreciate it, thanks!
Upvotes: 0
Views: 317
Reputation: 1427
You are trying to get content of empty variable items
... Replace
icon: items[Math.floor(Math.random()*icons .length)]
with:
icon: icons[Math.floor(Math.random()*icons .length)]
Because you haven't got saved pictures in variable items
but in variable icons
.
Upvotes: 1