admin管理员组文章数量:1306037
I need to make something happen when any google maps marker is clicked on. Im using the demo from this link as a starting point:
.html
UPDATE - ive tried the following:
$.each(markers, function(i, marker){
marker.click(function(){
alert('alert');
});
});
$.each(markers, function(i, marker){
$(marker).click(function(){
alert('alert');
});
});
UPDATE Ive tried adding this middle section to existing code:
$.each(markers, function(i, marker){
marker.setMap( checked ? map : null);
//added code begins
$(marker).click(function(){
alert('dfd');
});
//added code ends
});
I need to make something happen when any google maps marker is clicked on. Im using the demo from this link as a starting point:
http://gmap3/examples/tags.html
UPDATE - ive tried the following:
$.each(markers, function(i, marker){
marker.click(function(){
alert('alert');
});
});
$.each(markers, function(i, marker){
$(marker).click(function(){
alert('alert');
});
});
UPDATE Ive tried adding this middle section to existing code:
$.each(markers, function(i, marker){
marker.setMap( checked ? map : null);
//added code begins
$(marker).click(function(){
alert('dfd');
});
//added code ends
});
Share
Improve this question
edited Mar 16, 2012 at 16:31
skaffman
404k96 gold badges824 silver badges775 bronze badges
asked Feb 28, 2012 at 11:58
EvanssEvanss
23.2k100 gold badges322 silver badges556 bronze badges
3 Answers
Reset to default 3google.maps.event.addListener(marker, 'click', function() {
});
ref: https://code.google./apis/maps/documentation/javascript/events.html#UIEvents
Example : http://jsfiddle/diode/yXQwp/
Note that the OP is asking about doing this using the GMAP3 library, which is a jQuery plugin library that adds an API layer on top of the Google Maps layer. it is absolutely correct to say that the Google API is to use google.maps.addListener, but I think that the OP wants something that's closer to the GMAP3 example using addMarkers, but listening to the click event. With that in mind, I modified the example from GMAP3 and changed the mouseenter event to the click event and got rid of the mouseleave event.
For those wanting to do further playing, I created a jsFddle of this example.
Here's the source:
<!DOCTYPE HTML>
<html>
<head>
<style>
#map {
width: 400px;
height: 400px;
}
</style>
<script type="text/javascript" src="http://maps.google./maps/api/js?sensor=false"> </script>
<script type="text/javascript" src="http://gmap3/js/gmap3-4.1-min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#map').gmap3({
action: 'init',
options: {
center: [46.578498, 2.457275],
zoom: 5
}
}, {
action: 'addMarkers',
markers: [
{
lat: 48.8620722,
lng: 2.352047,
data: 'Paris !'},
{
lat: 46.59433,
lng: 0.342236,
data: 'Poitiers : great city !'},
{
lat: 42.704931,
lng: 2.894697,
data: 'Perpignan ! <br> GO USAP !'}
],
marker: {
options: {
draggable: false
},
events: {
click: function(marker, event, data) {
var map = $(this).gmap3('get'),
infowindow = $(this).gmap3({
action: 'get',
name: 'infowindow'
});
if (infowindow) {
infowindow.open(map, marker);
infowindow.setContent(data);
} else {
$(this).gmap3({
action: 'addinfowindow',
anchor: marker,
options: {
content: data
}
});
}
}
}
}
});
});
</script>
</head>
<body>
<div id="map" style="width: 400x; height: 400px"></div>
</body>
</html>
your question really doesn't entail much detail, but maybe you need something like this:
$.each(markers, function(i, marker){
marker.click(function(){ //maybe, its $(marker).click
console.log(marker);
});
});
edit: this couls work for you...
google.maps.event.addListener(marker, 'click', toggleBounce);
if you google that exact line, you get further pointers... good luck!
本文标签: jqueryJavaScript click event for any google maps markersStack Overflow
版权声明:本文标题:jquery - JavaScript click event for any google maps markers? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741812904a2398903.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论