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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:32:03+00:00 2026-05-28T20:32:03+00:00

I am reading points from a DB as JSON to create map markers and

  • 0

I am reading points from a DB as JSON to create map markers and an unstructured list on a page. After adding some code to customize the list elements the map stopped showing the marker icons on first request – until a page reload is issued. Is this due to timing out from the API? Could the list object be built from the array after the map is loaded or is there some other way to speed up the code that might eliminate the problem? The map loaded markers fine with double this number of markers (300+) so I know problem is as a result of adding the formatting to the list object. No clustering required. A demo version of the page is available here

Signed a JS n00b. Thanks.
……

JSON POWERED GOOGLEMAP

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

<script type="text/javascript" charset="utf-8"> 
var map;
    var infoWindow = new google.maps.InfoWindow();
    function initialize() {
        var myLatlng = new google.maps.LatLng(49.57154029531499,-125.74951171875);

        var myOptions = {
            zoom: 8,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.TERRAIN,
            streetViewControl: false
            }

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

        } /* end initialize function */


<!--  load points from database into Locations JSON -->

$(document).ready(function () {
    initialize();
    $.getJSON("map-service.php?action=listpoints", function(json) {

    if (json.Locations.length > 0) {
        for (i=0; i<json.Locations.length; i++) {
            var location = json.Locations[i];
                addMarker(location); 
                }
            }
        });

    //define grn icon as closed
    var greenicon = 'http://maps.google.com/mapfiles/ms/icons/green-dot.png';

    function addMarker(location) {
            if(location.datesummit == "0000-00-00") {
                var markerOptions = {map: map, title: location.name, position: new google.maps.LatLng(location.lat, location.lng),icon: greenicon};
                //create marker info window content
                var html='<B>'+location.name+'</B><BR> Register a summit <A href="http://goo.gl/Nl0UQ">here</A>  ';
                //create list element text and onclick          
                $("<li class=\"notclimbed\">")
                .html(location.name+"</li>") 
                .click(function(){ 
                    infoWindow.close();
                    infoWindow.setContent(html);
                    infoWindow.open(map, marker)
                }) 
                .appendTo("#list"); 
            }
            else{
                var markerOptions = {map: map, title: location.name, position: new google.maps.LatLng(location.lat, location.lng)};
                //create marker info window content
                var html='<B>'+location.name+'</B><BR> Summitted: '+location.datesummit+'<BR> By:'+location.summitlog;
                //create list element text and onclick  
                $("<li class=\"climbed\">")
                .html(location.name+"</li>") 
                .click(function(){ 
                    infoWindow.close();
                    infoWindow.setContent(html);
                    infoWindow.open(map, marker)
                }) 
                .appendTo("#list"); 
            }
            var marker = new google.maps.Marker(markerOptions);

            // add a listener to open an info window when a user clicks on one of the markers
            google.maps.event.addListener(marker, 'click', function() {
                infoWindow.close();
                infoWindow.setContent(html);
                infoWindow.open(map, marker);
                });

        }; // end of addmarker function
});
</script>
</head>


<body>
<div id="banner" {vertical-align:text-top;} >
    <img src="test.jpg" alt="Logo" style="width:150px;height:150px;vertical-align:middle">
    <img src="test.png" alt="Logo" style="vertical-align:middle">
</div>

<div id="map_canvas" >
        Map Here!
</div>

<div id="mindthegap"></div>

<div id="list" >    </div>
</body>
  • 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-28T20:32:04+00:00Added an answer on May 28, 2026 at 8:32 pm

    You need to make sure the map variable is initialized before you pass it to markerOptions.

    A bit of overzealous debugging showed me that on the times that the page fails, the map is still undefined.

    The $(document).ready() will usually occur before body.onload, so either put a call to initialize() at the very top of your $(document).ready(function() { … }); or put the code for initialize in there.

    Also, though not strictly necessary, you should consider encapsulating your map variable instead of using a global. What if you ever want to have 2 maps on one page?

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

Sidebar

Related Questions

When reading a post some points were given without example : To implement IEnumerable
I need some help understanding some of the points from Paul Graham’s What Made
My application have to load some points from internal sqlite database of android, and
I've been reading some posts about web performance, one of the points is to
I'm reading Javascript Web Applications, from O'Reilly. At various points in the book, the
I'm reading some numbers from a data source that represent x- and y-coordinates that
I'm not familiar with Filnet P8. My assumptions from reading some online docs is
After reading this old post from Clinton Begin (creator of iBatis) I really wonder
I'm having some trouble with multi-layer pointers. Basically I'm reading point locations from a
Can anyone point me in the right direction on this. From reading the FAQs

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.