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

  • SEARCH
  • Home
  • 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 8858903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:55:59+00:00 2026-06-14T14:55:59+00:00

I currently add markers to the map using the code below. I’d like to

  • 0

I currently add markers to the map using the code below. I’d like to be able to remove any one at any time by pushing a javascript command. Is this possible?

ex. place 5 markers.. removed the 3rd one while keeping the other 4.

$('#map').show();
var geocoder = new google.maps.Geocoder();
var address = document.getElementById("address").value +", " + document.getElementById("city").value;

geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
    var lat = results[0].geometry.location.lat();
    var lng = results[0].geometry.location.lng();
    locationsall[counter] = new Array();
    locationsall[counter][0] = address;
    locationsall[counter][1] = lat;
    locationsall[counter][2] = lng;
    var mapOptions = {
        zoom: 13,
        center: new google.maps.LatLng(lat, lng),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }

var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var marker, i;
for (i = 0; i < locationsall.length; i++) {  
    marker = new google.maps.Marker({
    position: new google.maps.LatLng(locationsall[i][1], locationsall[i][2]),
    map: map,
    title: 'You are here!'
    });
}
counter++;
} else {
    alert("Geocode was not successful for the following reason: " + status);
}

});
}

Edit 1:

        }).text("Remove").click(function() {
    var index2 = $tr2.index();
    $("#locationDeals input[type='hidden']").each(function() {
        this.name = this.name.replace(/\[(\d+)\]/, function(str2, number2) {
          return "[" + (+number2 > index2 - 1 ? number2 - 1 : number2) + "]";
        });
    });
    //locationsall[locations.indexOf(location)].setMap(null);
    $tr2.remove();
    locations.splice(locations.indexOf(location), 1);
    return false;
        }).appendTo($tdRemoveRow2);
  • 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-14T14:56:00+00:00Added an answer on June 14, 2026 at 2:56 pm

    Outside of your for loop define an Array that will hold all added markers. E.g. allMarkers = []

    Inside of your for loop after creating the marker, push it in said Array. E.g. allMarkers.push(marker)

    When you want to remove the first marker: allMarkers[0].setMap(null), or the third marker: allMarkers[2].setMap(null)

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

Sidebar

Related Questions

I am trying to add a bunch of map markers to a map using
Currently after successful login I add md5($username) md5($password) in cookies and then every time
Currently, I can add the creator_id like this in my controller: @entry = Entry.new(params[:entry].merge(:creator
I'm using jquery-ui-map to create a Google Maps instance like this: $('#CHMap').gmap({ mapTypeControl :
I have a script that loops and adds markers one at a time. I
I am trying to add infowindows to markers/pushpins on the map. ATM, it is
Currently i'm working with jquery-ui-map plugin. And i've faced one problem. Is it possible
i am currently on a Google Map Version 2 (sorry using the old version
I'm using GMap API v3 and Fluster2 to create a map with clustered markers
So I've got this script where I'm trying to add markers to a map

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.