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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:31:33+00:00 2026-05-30T17:31:33+00:00

I have gotten this to work a bit but can’t seem to figure out

  • 0

I have gotten this to work a bit but can’t seem to figure out what the exact phrasing to get the for loop to pass the correct value will be.

for(i=0; i < the_stores.length; i++) {
    uid = the_stores[i].id;

    // get the lat long and write info to the console
    geocoder.getLatLng(the_stores[i].address, function(point) { return callbackFunc(point, uid); });
}

function callbackFunc(point, myID) {
    if(point !== null) {
        console.log(point.toString());
        console.log(myID);
    } else {
        return false;
    }
}

I’m using the Google Maps API, v2. I want that for loop to pass in a different value of uid to the callback function for each iteration through the loop, but right now it passes in the same value every time. Anyone know how to get the desired effect here? I feel like I’m pretty close. Thank you!

  • 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-30T17:31:34+00:00Added an answer on May 30, 2026 at 5:31 pm

    What you are looking for is an “Immediately Invoked Function Expression”. Since JavaScript only has function scope, not block scope, all references to uid are being bound to the same variable.

    (For more, see: http://benalman.com/news/2010/11/immediately-invoked-function-expression/)

    Here’s a simple way to do it:

    for(i=0; i < the_stores.length; i++) {
      (function() {
        var uid = the_stores[i].id;
    
        // get the lat long and write info to the console
        geocoder.getLatLng(the_stores[i].address, function(point) { return callbackFunc(point, uid); });
      })();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sure this is very simple. I have gotten colorbox to work before, but
EDIT: Having gotten this to work under 32-bit, I'm now trying to get it
I have successfully gotten my low-level mouse hook code to work, but there are
I have never gotten this to work. What the heck am I doing wrong?
I've run into an issue that I can't seem to figure out the solution
I have a list of System.DirectoryServices.ActiveDirectory.Domain objects gotten via this method. How do I
I have tried for three days now and gotten nowhere on this.... I absolutely
I have gotten myself into a catch 22 and cannot seem to find my
I seem to have gotten confused as to what the css clear keyword means.
I'm having a great time learning Python, but I've just gotten a bit stuck

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.