Marker click event is not firing
up vote
0
down vote
favorite
I have taken on some code already in production and I have a problem with some markers not having a click event attached to them.
To try and get this working I have stripped back the code and just implemented the basic example shown in this page - https://developers.google.com/maps/documentation/javascript/examples/event-simple, inside the structure of my current code.
However, this doesn't work, the marker is set but the click event is not attached.
Attaching a click event to the map works.
Does anybody have any suggestions about what could be causing this?
init() {
this.loadScript(`https://maps.googleapis.com/maps/api/js?client=${this.apiClient}`);
}
loadScript(url) {
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
document.getElementsByTagName('body')[0].appendChild(script);
setTimeout(() => {
this.initMap();
}, 500);
}
initMap() {
const myLatlng = {lat: -25.363, lng: 131.044};
const map = new google.maps.Map(this.mapElement, {
zoom: 4,
center: myLatlng
});
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom'
});
map.addListener('center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function() {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function markerClick() {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}
google-maps-api-3 google-maps-markers
add a comment |
up vote
0
down vote
favorite
I have taken on some code already in production and I have a problem with some markers not having a click event attached to them.
To try and get this working I have stripped back the code and just implemented the basic example shown in this page - https://developers.google.com/maps/documentation/javascript/examples/event-simple, inside the structure of my current code.
However, this doesn't work, the marker is set but the click event is not attached.
Attaching a click event to the map works.
Does anybody have any suggestions about what could be causing this?
init() {
this.loadScript(`https://maps.googleapis.com/maps/api/js?client=${this.apiClient}`);
}
loadScript(url) {
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
document.getElementsByTagName('body')[0].appendChild(script);
setTimeout(() => {
this.initMap();
}, 500);
}
initMap() {
const myLatlng = {lat: -25.363, lng: 131.044};
const map = new google.maps.Map(this.mapElement, {
zoom: 4,
center: myLatlng
});
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom'
});
map.addListener('center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function() {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function markerClick() {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}
google-maps-api-3 google-maps-markers
1
Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
– boateng
Nov 9 at 15:16
1
The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
– geocodezip
Nov 9 at 15:48
Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with theclient
param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.
– Scott Francis
Nov 12 at 14:24
In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
– Scott Francis
Nov 16 at 7:09
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have taken on some code already in production and I have a problem with some markers not having a click event attached to them.
To try and get this working I have stripped back the code and just implemented the basic example shown in this page - https://developers.google.com/maps/documentation/javascript/examples/event-simple, inside the structure of my current code.
However, this doesn't work, the marker is set but the click event is not attached.
Attaching a click event to the map works.
Does anybody have any suggestions about what could be causing this?
init() {
this.loadScript(`https://maps.googleapis.com/maps/api/js?client=${this.apiClient}`);
}
loadScript(url) {
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
document.getElementsByTagName('body')[0].appendChild(script);
setTimeout(() => {
this.initMap();
}, 500);
}
initMap() {
const myLatlng = {lat: -25.363, lng: 131.044};
const map = new google.maps.Map(this.mapElement, {
zoom: 4,
center: myLatlng
});
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom'
});
map.addListener('center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function() {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function markerClick() {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}
google-maps-api-3 google-maps-markers
I have taken on some code already in production and I have a problem with some markers not having a click event attached to them.
To try and get this working I have stripped back the code and just implemented the basic example shown in this page - https://developers.google.com/maps/documentation/javascript/examples/event-simple, inside the structure of my current code.
However, this doesn't work, the marker is set but the click event is not attached.
Attaching a click event to the map works.
Does anybody have any suggestions about what could be causing this?
init() {
this.loadScript(`https://maps.googleapis.com/maps/api/js?client=${this.apiClient}`);
}
loadScript(url) {
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
document.getElementsByTagName('body')[0].appendChild(script);
setTimeout(() => {
this.initMap();
}, 500);
}
initMap() {
const myLatlng = {lat: -25.363, lng: 131.044};
const map = new google.maps.Map(this.mapElement, {
zoom: 4,
center: myLatlng
});
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom'
});
map.addListener('center_changed', function() {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function() {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function markerClick() {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
}
google-maps-api-3 google-maps-markers
google-maps-api-3 google-maps-markers
asked Nov 9 at 14:43
Scott Francis
192
192
1
Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
– boateng
Nov 9 at 15:16
1
The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
– geocodezip
Nov 9 at 15:48
Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with theclient
param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.
– Scott Francis
Nov 12 at 14:24
In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
– Scott Francis
Nov 16 at 7:09
add a comment |
1
Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
– boateng
Nov 9 at 15:16
1
The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
– geocodezip
Nov 9 at 15:48
Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with theclient
param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.
– Scott Francis
Nov 12 at 14:24
In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
– Scott Francis
Nov 16 at 7:09
1
1
Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
– boateng
Nov 9 at 15:16
Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
– boateng
Nov 9 at 15:16
1
1
The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
– geocodezip
Nov 9 at 15:48
The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
– geocodezip
Nov 9 at 15:48
Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with the
client
param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.– Scott Francis
Nov 12 at 14:24
Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with the
client
param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.– Scott Francis
Nov 12 at 14:24
In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
– Scott Francis
Nov 16 at 7:09
In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
– Scott Francis
Nov 16 at 7:09
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I make a few change and works
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom',
icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
});
map.addListener('center_changed', function () {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function () {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function () {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
marker.setMap(map);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I make a few change and works
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom',
icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
});
map.addListener('center_changed', function () {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function () {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function () {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
marker.setMap(map);
add a comment |
up vote
0
down vote
I make a few change and works
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom',
icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
});
map.addListener('center_changed', function () {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function () {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function () {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
marker.setMap(map);
add a comment |
up vote
0
down vote
up vote
0
down vote
I make a few change and works
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom',
icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
});
map.addListener('center_changed', function () {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function () {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function () {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
marker.setMap(map);
I make a few change and works
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom',
icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
});
map.addListener('center_changed', function () {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function () {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function () {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
marker.setMap(map);
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom',
icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
});
map.addListener('center_changed', function () {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function () {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function () {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
marker.setMap(map);
const marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Click to zoom',
icon: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png'
});
map.addListener('center_changed', function () {
// 3 seconds after the center of the map has changed, pan back to the
// marker.
window.setTimeout(function () {
map.panTo(marker.getPosition());
}, 3000);
});
marker.addListener('click', function () {
map.setZoom(8);
map.setCenter(marker.getPosition());
});
marker.setMap(map);
answered Nov 13 at 10:19
LDS
1946
1946
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53227914%2fmarker-click-event-is-not-firing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Not seeing where you calling the init(), may be better to embed the script in html bottom of the page as in your example.. Please upload your html..
– boateng
Nov 9 at 15:16
1
The posted code works (fiddle), please provide a Minimal, Complete, and Verifiable example that demonstrates your issue
– geocodezip
Nov 9 at 15:48
Thank you for your responses, I have found that the code I posted and works (as demonstrated by geocodezip the problem is with the
client
param in the url. If I remove this everything works (but with a map that says for development purposes only as a watermark.) I am running this through Adobe Experience Manager 6.4 and think a recent version upgrade may have caused this issue. I'll investigate further and post updates when I have them.– Scott Francis
Nov 12 at 14:24
In the end this was fixed simply by my client logging in to their Google Maps account. We were checking everything was ok there and it seemed so. The next time I refreshed the map it suddenly worked. In the end it was a wild goose chase, the code was correct, it seems the account had been blocked somehow.
– Scott Francis
Nov 16 at 7:09