Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:05:09+00:00 2026-06-14T13:05:09+00:00

Possible Duplicate: Google Maps API v3: How to remove all markers? I’m trying to

  • 0

Possible Duplicate:
Google Maps API v3: How to remove all markers?

I’m trying to delete the old markers and load new ones.

Here is the code I have that loads certain markers on page load – no issues here:

            (function() {

            var customIcons = {
  1: {
    icon: 'redmarker.png',
    shadow: 'markershadow.png'
  },
  2: {
    icon: 'purplemarker.png',
    shadow: 'markershadow.png'
  },
  3: {
    icon: 'silvermarker.png',
    shadow: 'markershadow.png'
  },
  4: {
    icon: 'goldmarker.png',
    shadow: 'markershadow.png'
  }
};


                window.onload = function(){
                    var MY_MAPTYPE_ID = 'custom';
                    var stylez = [ { "stylers": [ { "hue": "#00ccff" }, { "saturation": -100 }, { "lightness": 5 } ] },{ } ];
                    var latlng = new google.maps.LatLng(10, 10);
                    var options = {
                      zoom: 16,
                      center: latlng,
                      panControl: false,
                      zoomControl: false,
                  scaleControl: true,

                      mapTypeControlOptions: {
                        mapTypeIds: [MY_MAPTYPE_ID,google.maps.MapTypeId.SATELLITE]
                      },

                      mapTypeId: MY_MAPTYPE_ID
                    }; 
                    var map = new google.maps.Map(document.getElementById('map'), options);
                    var styledMapOptions = {
                        name: 'Map'
                    };
                    var jayzMapType = new google.maps.StyledMapType(stylez, styledMapOptions);
                    map.mapTypes.set(MY_MAPTYPE_ID, jayzMapType);


                    var infoWindow = new google.maps.InfoWindow;

  // Change this depending on the name of your PHP file
  downloadUrl("getxml.php", function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
      var name = markers[i].getAttribute("id");
      var address = markers[i].getAttribute("id");
      var type = markers[i].getAttribute("venue_type");
      var point = new google.maps.LatLng(
          parseFloat(markers[i].getAttribute("lat")),
          parseFloat(markers[i].getAttribute("lng")));
      var html = "<b>" + name + "</b> <br/>" + address;
      var icon = customIcons[type] || {};
      var marker = new google.maps.Marker({
        map: map,
        position: point,
        icon: icon.icon,
        shadow: icon.shadow
      });
      bindInfoWindow(marker, map, infoWindow, html);
    }
  });



//BUTTON SWITCHING ////////////////////////////////////////////////////////////
//BUTTON SWITCHING ////////////////////////////////////////////////////////////
//BUTTON SWITCHING ////////////////////////////////////////////////////////////
//BUTTON SWITCHING ////////////////////////////////////////////////////////////
//BUTTON SWITCHING ////////////////////////////////////////////////////////////
//BUTTON SWITCHING ////////////////////////////////////////////////////////////
//BUTTON SWITCHING ////////////////////////////////////////////////////////////
jQuery(document).delegate(".topCanBeActive", "click", function( e ) { 
    e.preventDefault();
    jQuery(".topCanBeActive").removeClass("topActive");
    jQuery(this).addClass("topActive");

    switch( this.id ){
            case 'all_activity_button':
                     alert("search");
          break;
        case 'events_button':

downloadUrl("getxml2.php", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var name = markers[i].getAttribute("id");
          var address = markers[i].getAttribute("id");
          var type = markers[i].getAttribute("venue_type");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));
          var html = "<b>" + name + "</b> <br/>" + address;
          var icon = customIcons[type] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,
            shadow: icon.shadow
          });
          bindInfoWindow(marker, map, infoWindow, html);
        }
      });


          break;
        case 'venues_button':
            alert("venues");
          break;
        case 'search_button':
            alert("search");          
          break;
    }
});


//END ////////////////////////////////////////////////////////////
//END ////////////////////////////////////////////////////////////
//END ////////////////////////////////////////////////////////////
//END ////////////////////////////////////////////////////////////
//END ////////////////////////////////////////////////////////////
//END ////////////////////////////////////////////////////////////
//END ////////////////////////////////////////////////////////////
//END ////////////////////////////////////////////////////////////


                }

                function bindInfoWindow(marker, map, infoWindow, html) {
  google.maps.event.addListener(marker, 'click', function() {


    infoWindow.setContent(html);
    infoWindow.open(map, marker);
  });
}

function downloadUrl(url, callback) {
  var request = window.ActiveXObject ?
      new ActiveXObject('Microsoft.XMLHTTP') :
      new XMLHttpRequest;

  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      request.onreadystatechange = doNothing;
      callback(request, request.status);
    }
  };

  request.open('GET', url, true);
  request.send(null);
}

function doNothing() {}

            })();

Now, I created a button section where if you press one button, a different xml file is loaded. Notice the section with the ////////////////////// However, upon clicking the button, nothing happens. The xml file itself is okay and loads the desired data. I also receive no errors in firebug.

Any ideas why this happens?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:05:10+00:00Added an answer on June 14, 2026 at 1:05 pm

    This question has been answered before.
    To view a well described answer visit:

    Google Maps API v3: How to remove all markers?

    First answer let you know the solution.

    –

    What it really tells you is that you have to store up the markers in a array and then loop then trough and setMap to null.

    Example:

    markerVar.setMap(null);
    

    Afterwards you can then unset/reset the array and fill in new markers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Remove marker in Google Maps Api v3 I'm trying to give users
Possible Duplicate: Looping through Markers with Google Maps API v3 Problem I have a
Possible Duplicate: Can Google Maps/Places 'autocomplete' API be used via AJAX? There seems to
Possible Duplicate: get all available fonts from google font api How we can retrieve
Possible Duplicate: Google Maps JS API v3 - Simple Multiple Marker Example On my
Possible Duplicate: Android:Google Maps API Key Signup : MD5 certification key I'm tryng to
Possible Duplicate: Trying to use Google Places API with JQuery's getJSON function I am
Possible Duplicate: Google Maps output=kml broken? I started to get Error when I'm trying
Possible Duplicate: json with google geocoding api json Uncaught SyntaxError: Unexpected token : $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true&callback=?',
Possible Duplicate: How to detect an android device whether it supports google maps API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.