0

id = "showmarkers" のボタンがクリックされたときに Google マップにマーカーを表示するコードを以下に記述しました。

私がしたいのは、同じボタンが再度クリックされたとき (または、id = "hidemarkers" で別のボタンがクリックされたとき) にマーカーが非表示になることです。

どんな助けでも大歓迎です、ありがとう

$(document).ready(function() {
$("#map").css({
    height: 500,
    width: 600
});
var myLatLng = new google.maps.LatLng(51.50754,-0.127894);
    MYMAP.init('#map', myLatLng, 13);

$("#showmarkers").click(function(e){
    MYMAP.placeMarkers('markers.xml');
});

});

var MYMAP = {
    map: null,
bounds: null
    }

MYMAP.init = function(selector, latLng, zoom) {
var myOptions = {
zoom:zoom,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

this.map = new google.maps.Map($(selector)[0], myOptions);
this.bounds = new google.maps.LatLngBounds();
}

MYMAP.placeMarkers = function(filename) {
$.get(filename, function(xml){
    $(xml).find("marker").each(function(){
        var name = $(this).find('name').text();
        var address = $(this).find('address').text();

        var lat = $(this).find('lat').text();
        var lng = $(this).find('lng').text();
        var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));

        MYMAP.bounds.extend(point);

        var marker = new google.maps.Marker({
            position: point,
            map: MYMAP.map
        });

        var infoWindow = new google.maps.InfoWindow();
        var html='<strong>'+name+'</strong.><br />'+address;
        google.maps.event.addListener(marker, 'click', function() {
            infoWindow.setContent(html);
            infoWindow.open(MYMAP.map, marker);
        });

    });
});
}
4

1 に答える 1