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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:48:32+00:00 2026-05-30T04:48:32+00:00

I really am a JS noob – I have never really used itbefore and

  • 0

I really am a JS noob – I have never really used itbefore and am struggling using the marker clusterer google provide. I have rad the documentation

here is the code

<script src="http://localhost/wheredidmytweetgo/js/markercluster.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(
    document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.setCenter(
    new GLatLng( 56.65622649350222, -19.86328125), 2);
    var mc = new MarkerClusterer(map);
    function createMarker(point, text, title) {
      var marker =
      new GMarker(point,{title:title});
      GEvent.addListener(
      marker, "click", function() {
        marker.openInfoWindowHtml(text);
      });
      return marker;
    }
    <?php

    foreach ($cluster_location as $location) {
    ?>
    var marker = createMarker(
    new GLatLng(<?php echo $location ?>),
    'Marker text <?php echo $location ?>',
    'Example Title text <?php echo $location ?>');
    map.addMarker(marker);
    <?php }
  ?>
  }
}

cluster location is just an array of lat and longs – My code is working fine when just using the add.overlay however there are too many to make the map readable hence the need for clustering. I do load the clustering JS which I have I have included.
I create the clusterer object and pass in map as defined.

var markers = [];
//create array

I know I can create a JS array and pass this in to

var mc = new MarkerClusterer(map, markers);

But I simply dont have the JS knowledge to create an array at this time (I intend to learn) and the Google documentation advises you can iterate and add one at a time using addMarker

Hi Tom – Thanksfor the info – I have tried doing what you advised and have came up with the below:

<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript" src="http://localhost/wheredidmytweetgo/js/markercluster.js">

    </script>

    <script type="text/javascript">
      function initialize() {
        var center = new google.maps.LatLng(37.4419, -122.1419);

        var map = new google.maps.Map(document.getElementById('map'), {
          'zoom': 13,
          'center': center,
          'mapTypeId': google.maps.MapTypeId.ROADMAP
        });

        var markers = [];
       <?php foreach ($cluster_location as $location) { ?>{
         var marker = new google.maps.Marker({'position': <?php echo $location;?>});
  markers.push(marker);
}
        <?
       }
       ?>
        var markerCluster = new MarkerClusterer(map, markers);
      }
      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <h3>A simple example of MarkerClusterer (100 markers)</h3>
    <p>
      <a href="?compiled">Compiled</a> |
      <a href="?">Standard</a> version of the script.
    </p>
    <div id="map-container"><div id="map"></div></div>
  </body>
</html>

But my map still loads empty. I’m using literally the most basic google provided code now and just loading my own markers in. I know my markers positioning should be okay because when I go to view my page source I can see

{

          var marker = new google.maps.Marker({'position': 40.0994425,-74.9325683});

         markers.push(marker);

          });

for each marker. any more help would really be appreciated!

  • 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-30T04:48:33+00:00Added an answer on May 30, 2026 at 4:48 am

    Please check the examples on google maps utilities library page (link).

    But basically to add instance of an object (a marker) to an array you have to define the array first so you need to do the var markers = []; above the loop where you create the markers. And then as you create the markers you have to add them to the markers array by calling the push method of an array (while you are at it go to MDN and read about arrays! if you want to learn it’s good time to start there – there is a tutorial about JS there as well (link).

    So inside of the foreach loop afer you’ve defined a marker just add it to the array markers.push(marker); This will make the markers available for the MarkerCluster initialization.

    In a longer term when you figure out javascript a bit better you’ll probably want to replace this part with either passing data as JSON object to the DOM so methods can handle it or even better – have the data for markers be retrieved with ajax query. But one step at a time I guess 🙂

    Maybe try the fun interactive tutorials at the http://www.codecademy.com? They are quite basic but seems like that’s exactly what you need

    EDIT:

    var marker,
        markers = [];
    
    <?php foreach ($cluster_location as $location) { ?>
        marker = new google.maps.Marker({'position': <?php echo $location;?>});
        markers.push(marker);
    <? } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a c# noob but I really need a professional's help. I am using
This is really a noob quick question. Imagine you have a struct called No
Ok. very much totally noob question but I really don't have a clue and
I am really new to XML and JDOM so I have a noob question,
I'm a noob, and I'm sorry because the question is really stupid. I have
Really stupid question, sorry, but I can't find it on google (I'm sure it's
Really ripping my hair out on this one. I have a JAAS Authentication Provider
Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return
This is really noob question. There is set of vim commands : command1 :
sorry, this is a really noob question... When I want to print part of

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.