I’m making a restaurant review website and am not sure why Marker isn’t working in this case.
The restaurant information are stored in mySQL database but it shouldn’t be related to this error.
The error is on this line
marker = new google.map.Marker({
I have multiple lines using Marker so I really don’t know what is the next step.
Tried troubleshooting but can’t seem to find anything wrong.
Can anybody lend a helping hand?
Here is my code:
function showMap(element) {
var item = element.getAttribute("item");
currentIndex = item;
var locations = [restaurant_array[item].address, restaurant_array[item].lat, restaurant_array[item].lng];
map = new google.maps.Map(document.getElementById("map"), { center: { lat: 1.8, lng: 110.9 }, zoom: 4 });
var infowindow = new google.maps.InfoWindow();
var marker, i;
var markers = [];
marker = new google.map.Marker({
position: new google.map.LatLng(locations[1], locations[2]),
map: map,
icon: {
url: "http://maps.google.com/mapfiles/ms/icons/restaurant.png"
}
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[0]);
infowindow.open(map.marker);
}
})(marker, i));
navigator.geolocation.getCurrentPosition(
(position) => {
const pos = {
lat: position.coords.latitude,
lng: position.coords.latitude
}
map.setCenter(pos);
map.setZoom(15);
marker = new google.maps.Marker({
position: new google.map.LatLng(locations[1], locations[2]),
map: map,
icon: {
url: "http://maps.google.com/mapfiles/ms/icons/red-dot.png"
}
})
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent("Your current Location");
infowindow.open(map, marker);
}
})(marker, i));
}
)
}