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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:33:34+00:00 2026-05-24T05:33:34+00:00

I am using Google Maps Javascript to create a map. I am needing to

  • 0

I am using Google Maps Javascript to create a map. I am needing to get a count of each marker that has ben created, and this count is placed in a DIV.
The scipt collects the count, however it displays a count for each marker.
For example if there are three markers returned from the query, 3 gets echod three times. If fourty three markers are created the number 43 gets echoed fourty three times in the DIV.

var MarkerCount;
var count = markerNodes.length;
var markercountEntry = createMarkerCount(count);
MarkerCount.appendChild(markercountEntry);

function createMarkerCount(count) {
    var div = document.createElement('div');
    var html = "<br/>" + count;
    div.innerHTML = html;
    div.style.marginBottom = '5px'; 
    return div;
}

Appreciate any assistance to help understand why I am getting this behaviour. The expected behavior is to write the results one time, not x amount of times depending on how many markers there are.

edit ——
Here is the complete code:

var icon = new google.maps.MarkerImage("./images/plum_flag.png", 
new google.maps.Size(35, 52), new google.maps.Point(0, 0), 
new google.maps.Point(0, 52));
var map;
var markers = [];
var infoWindow;
var sidebar;
var MarkerCount;

function load() {
  map = new google.maps.Map(document.getElementById("map"), {
    center: new google.maps.LatLng(36.1611, -116.4775),
    zoom: 6,
    mapTypeId: 'roadmap',
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DEFAULT}
  });
  infoWindow = new google.maps.InfoWindow();
  sidebar = document.getElementById("sidebar");
  }

 function formatPhone(telephone) { 
return "("+telephone.substring(0,3)+")"+telephone.substring(3,6)+"-"+telephone.substring(6,11); 
}


 function searchLocations() {
 var address = document.getElementById("addressInput").value;
 var geocoder = new google.maps.Geocoder();
 geocoder.geocode({address: address}, function(results, status) {
   if (status == google.maps.GeocoderStatus.OK) {
    searchLocationsNear(results[0].geometry.location);
   } else {
     alert(address + ' not found');
  }
  });
}

 function clearLocations() {
 infoWindow.close();
 for (var i = 0; i < markers.length; i++) {
   markers[i].setMap(null);
 }
 markers.length = 0; 
 sidebar.innerHTML = "";
 map.setCenter(new google.maps.LatLng(36.1611, -116.4775), 6);

}

 function searchLocationsNear(center) {
 clearLocations(); 

 var state = document.getElementById('stateSelect').value;
 var facility = document.getElementById('facility').value;
 var searchUrl = 'sql_to_xml.asp?facility=' + facility + '&state=' + state; 
 downloadUrl(searchUrl, function(data) { 
   var xml = parseXml(data);
   var markerNodes = xml.documentElement.getElementsByTagName("marker");
   var bounds = new google.maps.LatLngBounds();

var sidebar = document.getElementById('sidebar');
   sidebar.innerHTML = '';
   if (markerNodes.length == 0) {
     sidebar.innerHTML = 'No results found.';
     map.setCenter(new google.maps.LatLng(36.1611, -116.4775), 6);
     return;
   }

   var MarkerCount = document.getElementById('MarkerCount');
   MarkerCount.innerHTML = '';
   if (markerNodes.length == 0) {
     MarkerCount.innerHTML = 'No results found.';
     map.setCenter(new google.maps.LatLng(36.1611, -116.4775), 6);
     return;
   }

   for (var i = 0; i < markerNodes.length; i++) {
     var count = markerNodes.length;
     for (i=0;i<count;i++) 
     {     
     var markercountEntry = createMarkerCount(i);     
     MarkerCount.appendChild(markercountEntry); 
     } 
     var name = markerNodes[i].getAttribute("name"); 
     var address = markerNodes[i].getAttribute("address"); 
     var city = markerNodes[i].getAttribute("city");
     var state = markerNodes[i].getAttribute("state");
     var zipcode = markerNodes[i].getAttribute("zipcode");
     var telephone = markerNodes[i].getAttribute("telephone"); 
     var images = markerNodes[i].getAttribute("images"); 
     var url = markerNodes[i].getAttribute("url");
     var latlng = new google.maps.LatLng( 
          parseFloat(markerNodes[i].getAttribute("lat")), 
          parseFloat(markerNodes[i].getAttribute("lng")));

     var marker = createMarker(latlng, name, address, city, state, zipcode, telephone, images, url);
     bounds.extend(latlng);
     var sidebarEntry = createSidebarEntry(marker, name, address, city, state, zipcode, telephone, images, url);
     sidebar.appendChild(sidebarEntry);
     //var markercountEntry = createMarkerCount(count);
     //MarkerCount.appendChild(markercountEntry);
     }

     map.fitBounds(bounds);

     });
}

function createMarker(latlng, name, address, city, state, zipcode, telephone, images, url) { 
  var html = "<div id='infodiv'>" + name + "<br/><h4>" + address + "<br/>" + city + ", " + state + " " + zipcode + "<br/>" + (formatPhone(telephone)) + "</h4><div class='infoimage'><img src='" + images + "'></div><div class='footer'><a href='http://" + url + "'>" + url + "</a></div></div>";
  var marker = new google.maps.Marker({
    icon: icon, 
    map: map, 
    position: latlng 
  });
  markers.push(marker);

  google.maps.event.addListener(marker, 'click', function() {
    infoWindow.setContent(html);
    infoWindow.open(map, marker);
  });
  return marker;
}

function createSidebarEntry(marker, name, address, city, state, zipcode, telephone, images, url) {
  var div = document.createElement('div');
  var html = "<ul class='column'><li><div class='block'><a href='http://" + url + "'>" + name + "</a><br/>" + address + "<br/>" + city + ", " + state + " " + zipcode + "<br/>" + (formatPhone(telephone)) + "</div></li></ul>";
  div.innerHTML = html;
  div.style.marginBottom = '5px'; 
  return div;
}

 function createMarkerCount(count) {
  var div = document.createElement('div');
  var html = "<br/>" + count;
  div.innerHTML = html;
  div.style.marginBottom = '5px'; 
  return div;
}

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.responseText, request.status);
    }
  };

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

function parseXml(str) {
  if (window.ActiveXObject) {
    var doc = new ActiveXObject('Microsoft.XMLDOM');
    doc.loadXML(str);
    return doc;
  } else if (window.DOMParser) {
    return (new DOMParser).parseFromString(str, 'text/xml');
  }
}

function doNothing() {}
  • 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-05-24T05:33:35+00:00Added an answer on May 24, 2026 at 5:33 am

    Don’t put createMarkerCount in loop!

    So, change:

       for (var i = 0; i < markerNodes.length; i++) {
         var count = markerNodes.length;
         for (i=0;i<count;i++) 
         {     
         var markercountEntry = createMarkerCount(i);     
         MarkerCount.appendChild(markercountEntry); 
         } 
         var name = markerNodes[i].getAttribute("name"); 
         var address = markerNodes[i].getAttribute("address"); 
         var city = markerNodes[i].getAttribute("city");
         var state = markerNodes[i].getAttribute("state");
         var zipcode = markerNodes[i].getAttribute("zipcode");
         var telephone = markerNodes[i].getAttribute("telephone"); 
         var images = markerNodes[i].getAttribute("images"); 
         var url = markerNodes[i].getAttribute("url");
         var latlng = new google.maps.LatLng( 
              parseFloat(markerNodes[i].getAttribute("lat")), 
              parseFloat(markerNodes[i].getAttribute("lng")));
    
         var marker = createMarker(latlng, name, address, city, state, zipcode, telephone, images, url);
         bounds.extend(latlng);
         var sidebarEntry = createSidebarEntry(marker, name, address, city, state, zipcode, telephone, images, url);
         sidebar.appendChild(sidebarEntry);
         //var markercountEntry = createMarkerCount(count);
         //MarkerCount.appendChild(markercountEntry);
         }
    
         map.fitBounds(bounds);
    
         });
    }
    

    to

    var markercountEntry = createMarkerCount(markerNodes.length);     
    MarkerCount.appendChild(markercountEntry); 
       for (var i = 0; i < markerNodes.length; i++) {
         var name = markerNodes[i].getAttribute("name"); 
         var address = markerNodes[i].getAttribute("address"); 
         var city = markerNodes[i].getAttribute("city");
         var state = markerNodes[i].getAttribute("state");
         var zipcode = markerNodes[i].getAttribute("zipcode");
         var telephone = markerNodes[i].getAttribute("telephone"); 
         var images = markerNodes[i].getAttribute("images"); 
         var url = markerNodes[i].getAttribute("url");
         var latlng = new google.maps.LatLng( 
              parseFloat(markerNodes[i].getAttribute("lat")), 
              parseFloat(markerNodes[i].getAttribute("lng")));
    
         var marker = createMarker(latlng, name, address, city, state, zipcode, telephone, images, url);
         bounds.extend(latlng);
         var sidebarEntry = createSidebarEntry(marker, name, address, city, state, zipcode, telephone, images, url);
         sidebar.appendChild(sidebarEntry);
         //var markercountEntry = createMarkerCount(count);
         //MarkerCount.appendChild(markercountEntry);
         }
    
         map.fitBounds(bounds);
    
         });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create map (using the Google Maps JavaScript API V3 ) which
I'm using the Google Maps Javascript API so that I can have someone put
I'm using Google Maps Javascript API for showing a map in my site with
I'm using the Google Maps Javascript API and I have LatLng coordinates that are
It seems that licensing terms would prevent us from using Google Maps API in
Using the Google Maps API, how can I get the latitude and longitude of
I am using Google Maps JavaScript API v3. I want to wire up to
I am using Google Maps V3 API to create a polyline with 2 points.
Hi have an array of cities and want to create a google map using
I am building an application that has the functionality like 3 tabs created using

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.