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 7771673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:42:38+00:00 2026-06-01T16:42:38+00:00

I have a webpage that receives AJAX data with values listing_id, lat, lng using

  • 0

I have a webpage that receives AJAX data with values listing_id, lat, lng using $.getJSON. The callback function takes these series of values and creates a Google map marker for each set of listing_id, lat, lng. The marker is then pushed into an array markers and its listing_id into an array markersListingId.

var latLng = new google.maps.LatLng(json[i].lat, json[i].lng);
var marker = new google.maps.Marker({
                position: latLng,
                icon: base_url + 'images/template/markers/listing.png',
            });
markers.push(marker);
markersListingId.push(json[i].listing_id);

Problem: The problem arises when I want to select a specific Marker that corresponds to a particular listing_id, especially in more complicated situations with markers being deleted and added to the markers array.

I can have for loops looping through all the marker’s id in markersListingId array then using the loop’s index i to get the marker in markers array, but this will make tracking very tricky.

var id_to_select = 1234;
for(var i = 0; i < markersListingId; i++) {
    if(markersListingId[i] == id_to_select) {
        markers[i].setMap(null);
    }
}

Question: How can I store the markers so that I can easily select a specific marker by using its listing_id?

  • 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-01T16:42:39+00:00Added an answer on June 1, 2026 at 4:42 pm

    When you create the markers, instead of using an array, can you use a hash table?

    http://jsfiddle.net/j9J8x/

        var markers = {};
    
        //id goes in place of 1234
        n = 1234;
        markers[n] = new google.maps.Marker({
          map: map,
          position: new google.maps.LatLng(0,0)
        });
    
        s = '2234'
        markers[s] = new google.maps.Marker({
          map: map,
          position: new google.maps.LatLng(20,0)
        });
    
        google.maps.event.addListener(map, 'click', function(event) {
          k = 1234;
          markers[k].setMap(null);
          markers['2234'].setMap(null);
        });
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPad app that receives data using UDP sockets. And it has
I have a function that receives JSON data, it can be any length and
I have a webpage that displays a very large list of data. Since this
I have a AJAX call from my webpage sending the following data to my
I have a servlet that receives some POST data. Because this data is x-www-form-urlencoded,
I currently have a webpage where an iframe contains data that is stored into
I have a webpage that redirects to another webpage like this: http://www.myOtherServer.com/Sponsor.php?RedirectPage=http://mylink.com/whereIwasgoingtogo.html Then the
I have a webpage that I don't have the ability to change the underlying
I have a webpage that activates a print job on a printer. This works
I have a webpage that displays a calendar, and I want to change the

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.