1
I have the following code to add my markers:
function setParking(map)
{
var pointA = { lat: -16.113700, lng: -45.825545 };
var pointB = { lat: -15.284216, lng: -44.658747 };
var poinC = { lat: -16.139567, lng: -43.236152 };
setMap(map, pointA);
setMap(map, pointB);
setMap(map, poinC);
}
function setParkingMap(map, point)
{
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Loja Cascais</h1>' +
'<div id="bodyContent">'+
'<p><b>Morada:</b> Teste' +
'<p><b>Horário:</b> Teste 2 ' +
'</div>' +
'<button onclick="">Obter indicações</button>'
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: point,
map: map,
title: 'Teste'
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
}
function initMap() {
var mapOptions = {
zoom: 15, center: new google.maps.LatLng(38.696029, -9.424029)
}
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
setParking(map)
}
jQuery(document).ready(function () {
initMap();
});
What I intend to do now is when I click on the checkbox to call a function that erases me a Marker or more, I tried the following:
poinC.setMap(null)
, but it can’t be.
Does anyone know how I can do this?
Can provide the event and function where this should occur sff
– Miguel
<input id="chkOranTarif" type="checkbox" name="chkOranTarif" class="psform__checkbox" onchange="removeMap()"/> function removeMap(){ poinC.setMap(null)}. I don’t think it adds much but the idea is this
– HideCode
Debug: If you put an Alert inside the function it works? It’s not usually a problem but put ';' next to
setMap(null);
– Miguel
Maybe it’s an error in the syntax at points A and B you have
pointA/pointB
and in the C haspoinC
– Miguel
On the console the error you give me is the following: poinC.setMap is not a Function
– HideCode
Do you understand English well? If so, take a look here: http://stackoverflow.com/questions/13286913/google-maps-setmap-is-not-a-function and here http://stackoverflow.com/questions/14099556/why-setmapnullis-not-working-google-maps-apiv3
– Miguel
The problem is that I don’t want to have an array of points, I want to have everything individualized. as the selected checkbox may appear a Marker or not.
– HideCode