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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:57:22+00:00 2026-06-03T04:57:22+00:00

I have created the maps api below and have an array of addresses that

  • 0

I have created the maps api below and have an array of addresses that come from a database.
The map loads correctly, however I have the following issue.

  1. The dynamic Markers are not incrementing with the value of “i”.. so the map displays all markers with “1” and not “1,2,3,4,5”

    // Define Vars
    var pinColor = "FE7569";
    var marker, i;
    
    // Set default map center location
    var latlng = new google.maps.LatLng(-27.79014,153.18049);
    
    // Create pinShadow for each marker 
    var pinShadow = new google.maps.MarkerImage("http://chart.apis.google.com        /chart?chst=d_map_pin_shadow",
        new google.maps.Size(40, 37),
        new google.maps.Point(0, 0),
        new google.maps.Point(12, 35));
    
    // Function to create the dynamic marker
    function pinImage(i){
        return image = new google.maps.MarkerImage("http://www.googlemapsmarkers.com/v1/"+i+"/"+pinColor+"/", new google.maps.Size(21, 34), new google.maps.Point(0,0), new google.maps.Point(10, 34));
    }
    
    // Function to run once page has loaded
        function initialize(){      
    // Set Default settigns for google map
    var settings = {
        zoom: 10,
        center: latlng,
        mapTypeControl: true,
        mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
        navigationControl: true,
        navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
        mapTypeId: google.maps.MapTypeId.ROADMAP};
    
    // Start Google Maps and assign it to div on site
    var map = new google.maps.Map(document.getElementById("map_canvas"), settings);     
    
    // loop though total numner of address in array
    for (i = 1; i < total; i++) {  
        // Use geocoder to grab latlong for user inputed address
        geocoder.geocode( { 'address': address[i]}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                // Redefine map center location
                if (i = 1){ map.setCenter(results[0].geometry.location); }
    
                // Create dynamic markers on map as per the address array
                var marker = new google.maps.Marker({
                    map: map, 
                    position: results[0].geometry.location,
                    title:address[i],
                    zIndex: i,
                    // PROBLEM CODE --- Using the function below it creates all Markers with a "1" instead of the "i" value..??  
                    icon: pinImage(i),
                    shadow: pinShadow
                });         
            }
        });
        }
    }
    
  • 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-03T04:57:24+00:00Added an answer on June 3, 2026 at 4:57 am

    The old “function scope wrapper” trick (function(i) {...})(i) works here. Without it, the execution takes the final value of i. Also, if(i = 1) should be if(i == 1)

    To play around: http://jsfiddle.net/BK8vv/

    for (var i = 1; i < total; i++) {  
       (function(i) {
    
        // Use geocoder to grab latlong for user inputed address
        geocoder.geocode( { 'address': address[i]}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                // Redefine map center location
                if (i == 1){ map.setCenter(results[0].geometry.location); }
    
                // Create dynamic markers on map as per the address array
                        alert(i);
                var marker = new google.maps.Marker({
                    map: map, 
                    position: results[0].geometry.location,
                    title:address[i],
                    zIndex: i,
                    // PROBLEM CODE --- Using the function below it creates all Markers with a "1" instead of the "i" value..??  
                    icon: pinImage(i),
                    shadow: pinShadow
                });         
            }
           });
         })(i);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image created from the Google Maps API static map library and
I have created an infobox using google maps api v3 and infoBox from the
I have a simple object that get's geocoding data from the Google Maps API
I created a map using Google Maps API that highlights all Minnesota counties. Basically,
I have a Map object created through the google maps api and I want
For Google Maps V3, I have some code that created a marker when a
I've been working with Google Maps API v3 and created a map which allows
I have the following function (taken from Elevation Service @ Google Maps API )
I'm working on an application that uses the Google Maps API. I have no
I have created one table using the below command: create table Table1( Id int

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.