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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:00:43+00:00 2026-06-02T07:00:43+00:00

Got this code, that only works when alert (markers.length); is uncommented. When this javascript

  • 0

Got this code, that only works when alert (markers.length); is uncommented.

When this javascript alert not shown I dont get any Markers.. Really weird!!

In the body tag I have <body onload="load()" onunload="GUnload()">

Previoslly the load() function is called and other functions :

         function showAddress(address) {
           if (geocoder) {//+', '+init_street
    geocoder.getLatLng(address,
        function(point) {
                if (!point) {
                  document.getElementById("place").value="not found";
                  //alert(address + " not found");
                } else {
                //  document.getElementById("place").value=point.y.toFixed(4) + "," + point.x.toFixed(4);
                    map.setCenter(point, 16);
                    marker.setPoint(point);
                    //marker.openInfoWindowHtml(address);
                }
            }
    );
}
           }

         //from a point returns and address!
      function showPointAddress(response) {
  if (!response || response.Status.code != 200) {//not found
    //alert("Status Code:" + response.Status.code);
      document.getElementById("place").value="not found";
  } 
  else {//found
        map.setCenter(marker.getPoint(), 16);
        place = response.Placemark[0];
        document.getElementById("place").value=place.address;
        //document.getElementById("place").value=marker.getPoint().toUrlValue();
  }
         }


            // Creates a marker at the given point with the given number icon and text
          function createMarker(p,text) {
var marker = new GMarker(p);
if (text!=""){
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(text);});
      }
return marker;
      }


          ` var geocoder = null;`
          ` var map = null;`


      function load() {//loading the map
  if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.enableScrollWheelZoom();
        geocoder = new GClientGeocoder();

        if (init_street!=""){
            geocoder.getLatLng(init_street,function(point) {//set center point in map
                if (point){
                    map.setCenter(point, zoom);
                    map.addOverlay(createMarker(point,init_street));
                    map.openInfoWindow(point,init_street);
                }
            });
        }

        map.addControl(new GLargeMapControl());
        map.setMapType(G_NORMAL_MAP);           
  }
}`




function(data, responseCode) {
  if(responseCode == 200) {
        var texts = [];
        var addresses = [];       
        var xml = GXml.parse(data);
        var markers = xml.documentElement.getElementsByTagName("item");
        alert (markers.length);
        for (var i = 0; i < markers.length; i++) {  
            var address=markers[i].getElementsByTagName('address').item(0).childNodes.item(0).nodeValue;
            if (address!=null){
                //alert (address);
                var title=markers[i].getElementsByTagName('title').item(0).childNodes.item(0).nodeValue;
                var link=markers[i].getElementsByTagName('link').item(0).childNodes.item(0).nodeValue;
                var desc=markers[i].getElementsByTagName('description').item(0).childNodes.item(0).nodeValue;
                desc=desc.substr(0,220);//limit
                addresses.push(address);
                texts.push("<div style='width: 200px'><a target='_blank' href='" +link+"'>"+title+"</a><br />"+desc+"</div>");
            }//if
         }//for

        for (var i = 0; i < addresses.length; i++) { 
            geocoder.getLatLng(addresses[i], function (current) { 
                return function(point) { 
                    if (point) map.addOverlay(createMarker(point,texts[current]));    
                } 
            }(i)); 
        }

  }//if });

I Understand the issue of needing a callback function to load the markers, but Im lost..

Any help apreciated!! 😉

Thx in advanced!!

  • 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-02T07:00:45+00:00Added an answer on June 2, 2026 at 7:00 am

    This usually happens when fetching data with Ajax or similar. Basically when you fetch the data you need to utilize a callback function to wait for the data. If you don’t there is no data to execute on. However, if you pause the execution with a alert() the data will have been fetched in the background.

    Think of it as the waiting for the DOM to load before executing Javascript on the page.

    I can’t give you a better answer as you have not included the code that is calling the function you included.

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

Sidebar

Related Questions

I got this code today that works for jQuery v7. The problem is that
I got this javascript code from off the internet. It's a script that changes
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
I've got this code, that works in the latest version of firefox, opera and
Well ive got this code that creates a table from JSON data. If a
Ok, I've got this code that I've been using to spit out news to
I've got this really simple piece of code that I thought was the correct
I've got this code in the InitInstance function of a class that extends WinApp:
I've got a problem with inheritance and generics. This is the code that illustrates
I got some legacy code that has this: <?PHP if(isset($_GET['pagina'])==homepage) { ?> HtmlCode1 <?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.