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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:33:06+00:00 2026-06-07T03:33:06+00:00

SO I’ve read a bunch about Closure Issues, and I’m assuming that’s what this

  • 0

SO I’ve read a bunch about Closure Issues, and I’m assuming that’s what this is, but I’m not sure how to fix it.

The Problem: Basically, I only get 1 Marker, Which I’m assuming is because I’m using the same “marker” variable? But I’m not sure, nor do I see an easy solution to fix it. I’m sure there’s something obvious and I’d love a hand from someone who actually knows Javascript, as opposed to me who just screws with it until I get the result I need.

Thanks!

<script>
var geocoder;
var map;
var markersArray = [];
var plocation = [];

function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(39.50, -98.35);
var myOptions = {
    zoom: 4,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}

map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

function codeAddress() {
    //Delete Existing Markers
    clearOverlays();
    deleteOverlays();
    //Geocode and Add the New One + Results.
    var address = document.getElementById("address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        //add the center marker
        var patientslocation =results[0].geometry.location;
        addMarker(patientslocation, "Patient");
        //Zoom in on the Region.
        map.setZoom(10);
        //Call to Our API
        $.getJSON("map/search", { provider_type: "01", loc: '"'+patientslocation+'"' },function(data) {
            //Parse Results
            var htmlstring = "";
            var arraylength = data.length-1;
            console.log("Result Count (base 0): "+arraylength)
            $(data).each(function(i,val){

                //Build HTML String for Side Bar
                if (val.name){
                    htmlstring = htmlstring + "<h3>"+val.name+"</h3>";
                }
                if (val.address){
                    htmlstring = htmlstring + val.address +"<br/>";
                }
                if (val.phone){
                    htmlstring = htmlstring +val.phone +"<br/>";
                }
                //Build HTML Strings for Each Marker Hover

                //Load the Array of Markers
                plocation[i] = new google.maps.LatLng(val.lat, val.lng);
                console.log(i +" : " +plocation[i]);

                if(i === arraylength){
                    console.log("Load plocations called")
                    load_plocations();
                }
            });
            $('#prov_list').html(htmlstring);

        });

} else {
    alert("Geocode was not successful for the following reason: " + status);
}
});
}

function load_plocations(){
    $(plocation).each(function(k,v){
        console.log("Calling AddMarker: "+v)
        addMarker(v,k);
    });
}

function addMarker(location, name) {
   console.log("Adding Marker: "+location)
    marker = new google.maps.Marker({
        position: location,
        map: map
    });
    markersArray.push(marker);
}
//Clears the Markers from the map.
function clearOverlays() {
    console.log("Clearing Overlays");
    if (markersArray) {
        for (i in markersArray) {
            markersArray[i].setMap(null);
        }
    }
}

// Deletes all markers in the array by removing references to them
function deleteOverlays() {
    console.log("Deleting Overlays");
    if (markersArray) {
        for (i in markersArray) {
            markersArray[i].setMap(null);
        }
        markersArray.length = 0;
    }
}

  • 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-07T03:33:07+00:00Added an answer on June 7, 2026 at 3:33 am

    Try declaring marker using var:

    var marker = new google.maps.Marker({
    

    That will make it a locally-scoped object, thus creating a new one for each iteration.

    Without the var, it becomes global (ie, scoped to the window object). I’m not 100% sure but I think this may, as you wrote, overwrite the same marker on each iteration, rather than creating a new one.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.