Javascript 谷歌地图更改标记图标点击

Javascript 谷歌地图更改标记图标点击,javascript,google-maps,Javascript,Google Maps,如何在单击标记(在单击事件上)时更改标记图标,并在单击其他标记时将其返回到正常图标 如何加载已单击标记的地图 此外,如果有可能添加一些动画,如点击图标时的过渡 function initialize() { /* Lat. and Lon. of the center of the map */ var myCenter = new google.maps.LatLng(42.8012564, 10.75113); // Create a map object, and

如何在单击标记(在单击事件上)时更改标记图标,并在单击其他标记时将其返回到正常图标

如何加载已单击标记的地图

此外,如果有可能添加一些动画,如点击图标时的过渡

function initialize() {
    /* Lat. and Lon. of the center of the map */
    var myCenter = new google.maps.LatLng(42.8012564, 10.75113);

    // Create a map object, and include the MapTypeId to add
    // to the map type control.
    var mapOptions = {
        zoom: 14,               //zoom level
        center: myCenter,       //center position
        scrollwheel: false,     //zoom when scroll disable
        zoomControl: true,      //show control zoom
        disableDefaultUI: true,
        mapTypeControlOptions: {
        mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style'],
        }
    };

    var map = new google.maps.Map(document.getElementById('map'),mapOptions);

    var image1 = 'http://puntaala.noonicbeta.com/wp-content/themes/Wordpress/img/marker-grey.svg';



                  var marker2 = new google.maps.Marker({
                      position: new google.maps.LatLng(42.80207599824027, 10.756003014830668),
                      map: map,
                      icon: image1,
                      title: 'Hotel',
                      description: 'Magna exercitation id culpa eiusmod velit veniam. Cillum eiusmod irure dolore officia proident eiusmod Lorem dolore. Enim cupidatat esse laborum minim sint laborum ad duis ea est adipisicing incididunt ut veniam. Aliqua exercitation aute nostrud labore cupidatat velit commodo tempor minim voluptate non quis voluptate. Cupidatat aute velit est reprehenderit eu fugiat aliquip est do […]',
                      luogo: 'LA MAREMMA',
                      indirizzo: 'Costigliole della Pescaia',
                  });

                  function showClick (marker) {
                  var title = document.getElementById('title');
                  var description = document.getElementById('description');
                  var luogo = document.getElementById('luogo');
                  var indirizzo = document.getElementById('indirizzo');
                  title.innerHTML=marker.title;
                  description.innerHTML=marker.description;
                  indirizzo.innerHTML=marker.indirizzo;
                  luogo.innerHTML=marker.luogo;
                  marker.setIcon("http://puntaala.noonicbeta.com/wp-content/themes/Wordpress/img/marker.svg");
                  }

                  google.maps.event.addListener(marker2, 'click', function() {
                  showClick(marker2);
                  });


                  var marker1 = new google.maps.Marker({
                      position: new google.maps.LatLng(42.8012564, 10.75113),
                      map: map,
                      icon: image1,
                      title: 'Roccaforte',
                      description: 'ex ex reprehenderit aute exercitation cupidatat deserunt irure cillum sit ad culpa aliqua aliqua cupidatat anim exercitation commodo incididunt proident adipisicing fugiat excepteur elit voluptate incididunt minim esse ea incididunt voluptate amet ipsum quis sunt ullamco non consequat non eiusmod dolore nulla occaecat mollit pariatur cupidatat aliquip adipisicing voluptate nulla esse labore ad ipsum quis […]',
                      luogo: 'La Maremma',
                      indirizzo: 'Costigliole della Pescaia',
                  });

                  function showClick (marker) {
                  var title = document.getElementById('title');
                  var description = document.getElementById('description');
                  var luogo = document.getElementById('luogo');
                  var indirizzo = document.getElementById('indirizzo');
                  title.innerHTML=marker.title;
                  description.innerHTML=marker.description;
                  indirizzo.innerHTML=marker.indirizzo;
                  luogo.innerHTML=marker.luogo;
                  marker.setIcon("http://puntaala.noonicbeta.com/wp-content/themes/Wordpress/img/marker.svg");
                  }

                  google.maps.event.addListener(marker1, 'click', function() {
                  showClick(marker1);
                  });

          }
google.maps.event.addDomListener(window, 'load', initialize);
</script>
函数初始化(){
/*地图中心的纬度和经度*/
var myCenter=newgoogle.maps.LatLng(42.8012564,10.75113);
//创建地图对象,并包括要添加的MapTypeId
//到映射类型控件。
变量映射选项={
缩放:14,//缩放级别
中心:myCenter,//中心位置
滚轮:false,//禁用滚动时缩放
zoomControl:true,//显示控件缩放
disableDefaultUI:true,
mapTypeControlOptions:{
MapTypeId:[google.maps.MapTypeId.ROADMAP,'map_style'],
}
};
var map=new google.maps.map(document.getElementById('map'),mapOptions);
var image1=http://puntaala.noonicbeta.com/wp-content/themes/Wordpress/img/marker-grey.svg';
var marker2=新的google.maps.Marker({
位置:new google.maps.LatLng(42.80207599824027,10.756003014830668),
地图:地图,
图标:image1,
标题:“酒店”,
描述:“大型实习是对威尼斯人的过失。实习是对威尼斯人的惩罚。实习是对威尼斯人的惩罚。实习是对威尼斯人的惩罚。实习是对威尼斯人的惩罚。实习是对普通人的惩罚。实习是对普通人的惩罚这是欧盟富国的代表,也是我们的目标,
罗戈:“拉马雷玛”,
indirizzo:“Costigliole della Pescaia”,
});
功能显示单击(标记){
var title=document.getElementById('title');
var description=document.getElementById('description');
var luogo=document.getElementById('luogo');
var indirizzo=document.getElementById('indirizzo');
title.innerHTML=marker.title;
description.innerHTML=marker.description;
indirizzo.innerHTML=marker.indirizzo;
luogo.innerHTML=marker.luogo;
marker.setIcon(“http://puntaala.noonicbeta.com/wp-content/themes/Wordpress/img/marker.svg");
}
google.maps.event.addListener(marker2,'click',function(){
showClick(marker2);
});
var marker1=新的google.maps.Marker({
位置:新google.maps.LatLng(42.8012564,10.75113),
地图:地图,
图标:image1,
标题:“Roccaforte”,
描述:“前代表人或实习医生应承担责任,不应承担责任,不应承担责任,不应承担责任,不应承担责任,不应承担责任,不应承担责任,不应承担责任,不应承担责任,不应承担责任。”因为它的意思是“不存在劳动和自然权利[&hellip;]”,
罗戈:“拉马雷玛”,
indirizzo:“Costigliole della Pescaia”,
});
功能显示单击(标记){
var title=document.getElementById('title');
var description=document.getElementById('description');
var luogo=document.getElementById('luogo');
var indirizzo=document.getElementById('indirizzo');
title.innerHTML=marker.title;
description.innerHTML=marker.description;
indirizzo.innerHTML=marker.indirizzo;
luogo.innerHTML=marker.luogo;
marker.setIcon(“http://puntaala.noonicbeta.com/wp-content/themes/Wordpress/img/marker.svg");
}
google.maps.event.addListener(marker1,'click',function(){
显示单击(标记1);
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);
如何在单击标记(在单击事件上)时更改标记图标,并在单击其他标记时将其返回到正常图标

您可以使用谷歌地图api来使用标记的“信息窗口”功能。只有一个活动窗口的处理已经完成。你可以检查一下。 但是,如果您想自己做,您可以全局保存数组中的所有标记,并具有“取消选择”除您刚才选择的标记之外的所有其他标记的功能。就像你的“showClick(marker)”功能一样,正好相反

如何加载已单击标记的地图

为此,您可以在初始化函数末尾调用showClick(marker1)函数,或者在使用google maps api中的“信息窗口”时,您可以调用infowindow。如果初始化函数为,则在末尾分别打开(map,marker)

此外,如果可以添加一些动画,如点击图标时的过渡

function initialize() {
    /* Lat. and Lon. of the center of the map */
    var myCenter = new google.maps.LatLng(42.8012564, 10.75113);

    // Create a map object, and include the MapTypeId to add
    // to the map type control.
    var mapOptions = {
        zoom: 14,               //zoom level
        center: myCenter,       //center position
        scrollwheel: false,     //zoom when scroll disable
        zoomControl: true,      //show control zoom
        disableDefaultUI: true,
        mapTypeControlOptions: {
        mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style'],
        }
    };

    var map = new google.maps.Map(document.getElementById('map'),mapOptions);

    var image1 = 'http://puntaala.noonicbeta.com/wp-content/themes/Wordpress/img/marker-grey.svg';



                  var marker2 = new google.maps.Marker({
                      position: new google.maps.LatLng(42.80207599824027, 10.756003014830668),
                      map: map,
                      icon: image1,
                      title: 'Hotel',
                      description: 'Magna exercitation id culpa eiusmod velit veniam. Cillum eiusmod irure dolore officia proident eiusmod Lorem dolore. Enim cupidatat esse laborum minim sint laborum ad duis ea est adipisicing incididunt ut veniam. Aliqua exercitation aute nostrud labore cupidatat velit commodo tempor minim voluptate non quis voluptate. Cupidatat aute velit est reprehenderit eu fugiat aliquip est do [&hellip;]',
                      luogo: 'LA MAREMMA',
                      indirizzo: 'Costigliole della Pescaia',
                  });

                  function showClick (marker) {
                  var title = document.getElementById('title');
                  var description = document.getElementById('description');
                  var luogo = document.getElementById('luogo');
                  var indirizzo = document.getElementById('indirizzo');
                  title.innerHTML=marker.title;
                  description.innerHTML=marker.description;
                  indirizzo.innerHTML=marker.indirizzo;
                  luogo.innerHTML=marker.luogo;
                  marker.setIcon("http://puntaala.noonicbeta.com/wp-content/themes/Wordpress/img/marker.svg");
                  }

                  google.maps.event.addListener(marker2, 'click', function() {
                  showClick(marker2);
                  });


                  var marker1 = new google.maps.Marker({
                      position: new google.maps.LatLng(42.8012564, 10.75113),
                      map: map,
                      icon: image1,
                      title: 'Roccaforte',
                      description: 'ex ex reprehenderit aute exercitation cupidatat deserunt irure cillum sit ad culpa aliqua aliqua cupidatat anim exercitation commodo incididunt proident adipisicing fugiat excepteur elit voluptate incididunt minim esse ea incididunt voluptate amet ipsum quis sunt ullamco non consequat non eiusmod dolore nulla occaecat mollit pariatur cupidatat aliquip adipisicing voluptate nulla esse labore ad ipsum quis [&hellip;]',
                      luogo: 'La Maremma',
                      indirizzo: 'Costigliole della Pescaia',
                  });

                  function showClick (marker) {
                  var title = document.getElementById('title');
                  var description = document.getElementById('description');
                  var luogo = document.getElementById('luogo');
                  var indirizzo = document.getElementById('indirizzo');
                  title.innerHTML=marker.title;
                  description.innerHTML=marker.description;
                  indirizzo.innerHTML=marker.indirizzo;
                  luogo.innerHTML=marker.luogo;
                  marker.setIcon("http://puntaala.noonicbeta.com/wp-content/themes/Wordpress/img/marker.svg");
                  }

                  google.maps.event.addListener(marker1, 'click', function() {
                  showClick(marker1);
                  });

          }
google.maps.event.addDomListener(window, 'load', initialize);
</script>
谷歌地图api也支持这一点。你可以去看看这是怎么可能的