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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:01:49+00:00 2026-05-11T17:01:49+00:00

My code : http://jsbin.com/epuxu With help from SO, I managed to get addresses geocoded

  • 0

My code: http://jsbin.com/epuxu

With help from SO, I managed to get addresses geocoded and their according pins placed on the map. The problem is that I can’t select the coordinates in order to append a #message div to it on the map because I don’t have the coordinates anymore.

I suspect I’m doing something wrong in this section:

/* Message
--------------------*/
$("#message").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));

    function displayPoint(marker, index){
        $("#message").hide();

        var moveEnd = GEvent.addListener(map, "moveend", function(){
            var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
            $("#message")
                .fadeIn()
                .css({ top:markerOffset.y, left:markerOffset.x });

            GEvent.removeListener(moveEnd);
        });
        map.panTo(marker.getLatLng());
    }

it works when I use the original coordinate code (this is commented out on jsbin):

var markers = [
    [39.729308,-121.854087],
    [39.0,-121.0]
    ];

    for (var i = 0; i < markers.length; i++) {
        var point = new GLatLng(markers[i][0], markers[i][1]);
        marker = new GMarker(point);
        map.addOverlay(marker);
        markers[i] = marker;
    }

but I need help getting it to work with this current code:

function showAddress(markers) {
    if (geocoder) {
        geocoder.getLatLng(markers,
            function(point) {
                if (!point) {
                    alert(markers + " not found");
                } else {
                    marker = new GMarker(point);
                    map.addOverlay(marker);
                    markers[i] = marker;
                }
            }
        );
    }
}

for (var i = 0; i < markers.length; i++) {
    showAddress(markers[i]);
}

I’m kinda new to utilizing the google maps api, so any insight on what I’m doing wrong would be very helpful. Thanks =]

  • 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-11T17:01:49+00:00Added an answer on May 11, 2026 at 5:01 pm

    I’m afraid there were quite a few things wrong with your code 😛

    I had to do a bit of plastic surgery but here’s the result: http://jsbin.com/atofe

    The following is a description of the changes I made. Let me know if you need help understanding anything.


    <script type="text/javascript">
      document.write(marker);
    </script>
    

    I had to comment this out since it was causing an error. I’m guessing you left it in there by mistake.

    <script type="text/javascript">
      // document.write(marker);
    </script>
    

    var markers = [
      ["624 Nord Ave #20, Chico CA"],
      ["200 Nord Ave, Chico CA"],
      ["100 Nord Ave, Chico CA"],
      ["5th and Ivy, Chico CA"]
    ];
    

    Since we are using addresses instead of coordinates, you don’t need to (in fact you shouldn’t because it only complicates things) encapsulate each string in an array. I also renamed it to addresses to make it more clear and prevent conflicts with the actual markers (more on that later).

    var addresses = [
      "624 Nord Ave #20, Chico CA",
      "200 Nord Ave, Chico CA",
      "100 Nord Ave, Chico CA",
      "5th and Ivy, Chico CA"
    ];
    

    function showAddress(markers) {
      if (geocoder) {
        geocoder.getLatLng(markers,
          function(point) {
            if (!point) {
              alert(markers + " not found");
            } else {
              marker = new GMarker(point);
              map.addOverlay(marker);
              markers[i] = marker;
            }
          }
        );
      }
    }
    
    for (var i = 0; i < markers.length; i++) {
      showAddress(markers[i]);
    }
    
    
    /* Add Markers to List
    --------------------*/
    $(markers).each(function(i,marker){
      $("<li>")
        .html(i+" - "+marker)
        .click(function(){
          displayPoint(marker, i);
        })
        .appendTo("#list");
      GEvent.addListener(marker, "click", function(){
        displayPoint(marker, i);
      });
    });
    

    This is where I had to make the most changes.
    You made a couple of significant mistakes here.

    First, you re-used the variable markers when you should have used a new name. In the process you wrote over the array of address strings and misunderstood where things were stored (This is why I renamed the array of address strings to addresses).

    Second, you tried to add the markers to the list before the geocoder actually returned its response. I think you didn’t realize that getLatLng is an asynchronous function, so it executes the callback function only after the geocoder returns its response. Since you didn’t wait for the response, it rendered the “Add markers to list” section useless as the markers had not been retrieved yet.

    So, to fix these issues I moved the “Add markers to list” section inside the new handleGeocoderResponse function. This ensures the markers are added to the list only after the geocoder response is returned. I also had to use a double-closure since we are using a loop along with an asynchronous function.

    function handleGeocoderResponse(addr, j) {
      /*
        These are closures. We have to return a function
        that contains our Geocoder repsonse handling code
        in order to capture the values of "addr" and "j"
        as they were when they were passed in.  
      */
      return (function(point) {
    
        if (!point) {
          alert(addr + " not found");
        }
        else {
          var marker = new GMarker(point);
          map.addOverlay(marker);
    
          /* Add markers to list
          ------------------------*/
          $("<li>")
            .html(j + " - " + addr)
            .click(function(){
              displayPoint(marker, j);
            })
            .appendTo("#list");
    
          GEvent.addListener(marker, "click", function(){
            displayPoint(marker, j);
          });
        }
    
      });
    }
    
    for (var i = 0; i < addresses.length; i++) {
      if (geocoder) {
        var address = addresses[i];
        geocoder.getLatLng(
          address,
          handleGeocoderResponse(address, i)
        );
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer to script it to a file try: http://www.codeproject.com/KB/database/ScriptDiagram2005.aspx I would… May 11, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer If you want only to know the structure itself, you… May 11, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer This article is great in terms of how to set… May 11, 2026 at 6:00 pm

Related Questions

I am trying to find a way to load a JSON page to display
Here is a brief overview of what I am doing, it is quite simple
I'm using an HTML sanitizing whitelist code found here: http://refactormycode.com/codes/333-sanitize-html I needed to add
I have an odd edge case right now in that a response code from
I've followed the tutorials for setting up Apache with mod_wsgi to interface cherrypy and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.