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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:12:58+00:00 2026-06-12T14:12:58+00:00

I have the following code, and having read this , i understand it wont

  • 0

I have the following code, and having read this, i understand it wont work because the getJSON call is asynchronous. How do i need to change this so that the MarkerClusterer function gets triggered with a full set of markers? I’ve tried putting the MarkerClusterer function inside the getJSON call but with no luck…

var mcOptions = {gridSize: 50, maxZoom: 9};
var markers = [];

function parse_json(json) {
  if (json.length > 0) {
    for (i=0; i<json.length; i++) {
        var report = json[i];  
        var latLng = new google.maps.LatLng(report.latitude, report.longitude);
        markers[i] = new google.maps.Marker({
            position: latLng, 
            title: report.name + ' ' + report.surf_size_ft_round, 
            url: "/place/"+report.slug 
        });                     

        google.maps.event.addListener(markers[i], 'click', function() {
          window.location.href = markers[i].url;
        }); 
        markers.push(markers[i]);
    }
  } 
}; 


$.getJSON('<%= request.fullpath + ".json" %>', function(stream) {   
if (stream.length > 0) {
  parse_json(stream);
  alert(markers[1].title);  //sanity check - gives result
  }
});   


    alert(markers[5].title);  // sanity check - empty 
var mc = new MarkerClusterer(map, markers, mcOptions);
  • 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-12T14:12:59+00:00Added an answer on June 12, 2026 at 2:12 pm

    Why not put this code snippet:

    mc = new MarkerClusterer(map, markers, mcOptions);
    

    inside the anonymous callback function in your $.getJSON? Just declare var mc; somewhere outside the $.getJSON scope to be able to have access to it elsewhere.

    Alternatively, you can fire an event at the end of your parse_json function, listen to that event and then fire up another function that creates your MarkerClusterer object when the event has fired. Check this out: How to trigger event in JavaScript?

    EDIT:

    Upon inspecting your code a bit more, I can see that you set markers[i] to a new Marker instance and then push onto the markers array that same instance. You probably want to either set markers[i] to a new Marker instance or you want to create a var marker, setting it to a new Marker instance and then pushing on the markers array.

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

Sidebar

Related Questions

Having read around this site I thought the following code would return the ID
I'm having an issue with rails involving javascript. Basically, I have the following code:
I am having a link <a id=test href=text.php>test</a> I have the following jquery code
I'm having an issues with bottle python where I have the following code import
Not sure if I worded this correctly ... but I have the following code:
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have following code for loading image from url in xml parsing endElement method
I have following code for inserting data into database using PDO. It inserts data

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.