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

  • Home
  • SEARCH
  • 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 7982073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:34:05+00:00 2026-06-04T10:34:05+00:00

I’m using Google Maps JavaScript API V2 to mark locations saved in an array.

  • 0

I’m using Google Maps JavaScript API V2 to mark locations saved in an array. Markers with different coordinates are displayed well, but I have no idea how to display various markers with the same coordinates. I need it because an array of locations can have the same coordinates, but with a different description. What is the way to display those different descriptions?

The code where markers are added is:

var map;

    function loadEarth(mapdiv) {
        if (GBrowserIsCompatible()) {
            if(!mapdiv)
                return true;
            map=new GMap2(document.getElementById("map"));
            map.enableDoubleClickZoom();
            map.enableScrollWheelZoom();
            map.addControl(new GMapTypeControl());
            map.addControl(new GSmallMapControl());
            map.setCenter(new GLatLng(40.186718, -8.415994),13);
            }
    }
    function createMarker(point, number, description) {
        var marker = new GMarker(point);
        marker.value = number;
        GEvent.addListener(marker, "click", function() {
        var myHtml = "<b>#" + number + "</b><br/>" + description;
            map.openInfoWindowHtml(point, myHtml);
        });
        return marker;
    }

…

for(var i=0; i<gl_list.length; i++){
   var point = new GLatLng(gl_list[i].Latitude,gl_list[i].Longitude);
   description = "Visited place : "+gl_list[i].nome+" on : "+gl_list[i].data;
   map.addOverlay(createMarker(point, i + 1, description));
}

Thanks for your attention.

  • 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-04T10:34:06+00:00Added an answer on June 4, 2026 at 10:34 am

    I very often have the exact same problem on my map and found myself worrying about the same multiple markers issues: which marker is on top? how does a user see them all? etc.

    Eventually, I decided that the problem wasn’t actually about markers; its really about a specific point on the map. From a user perspective, they could care less about the markers or any of the mechanics around the markers. All they really care about is the information associated with that location. From that perspective, the challenge is finding a way to provide the user a way to view the associated information in a straightforward way. So I decided to merge all of the markers that occupy the same location into a single marker that includes all of the information that matters to the user.

    Step-by-step, here is the approach I use to solve the multiple markers in the same location problem:

    Step 1: Sort the marker data to allow identification of the markers that occupy the same location:

    gl_list.sort( function( a, b ) {
        var aLat = a.Latitude, bLat = b.Latitude;               
        if ( aLat !== bLat ) { return aLat - bLat; }
        else { return a.Longitude - b.Longitude; }
    });
    

    Step 2: Add a new function that creates a “special” marker for colocated members of the gl_list array:

    var specialMarkers = null;
    
    function createSpecialMarker( specialMarkers ) {
        var infoWinContent = "<table class='special-infowin-table'>";
    
        for ( var i = 0; i < specialMarkers.length; i++ ) {
            infoWinContent +=
                "<tr>" +
                "<td class='special-table-label'>" +
                    "Visited Place [" + (i+1) + "]" +
                "</td>" + 
                "<td class='special-table-cell'>" +
                    specialMarkers[i].nome + " on : " + specialMarkers[i].data +
                "</td></tr>";
        }
        infoWinContent += "</table>";
    
        var mrkrData = specialMarkers[0];
        var point = new GLatLng( mrkrData.Latitude, mrkrData.Longitude );
        var marker = new GMarker( point );
        GEvent.addListener(marker, "click", function() {
        map.openInfoWindowHtml( point, infoWinContent );
    });
    
        return marker;
    }
    

    Step 3: Iterate over the marker data, identify groupings that have the same location, show them on the map using a special marker, and handle all of the marker data at other locations “normally”:

    for ( var i = 0; i < gl_list.length; i++ ) {
        var current = gl_list[i];
        var coLocated = null;
        var j = 0, matchWasFound = false;
    
        if ( i < ( gl_list.length - 1 ) ) {
            do {
                var next = assetData[ i + ++j ];
                if ( next !== undefined ) {    //just to be safe
                    if ( next.Latitude === current.Latitude &&
                            next.Longitude === current.Longitude ) {
                        matchWasFound = true;
                        if ( coLocated === null ) {
                            coLocated = new Array( current, next);
                        }
                        else { coLocated.push( next ); }
                    }
                    else { matchWasFound = false; }
                }
                else { matchWasFound = false; }
            }
            while ( matchWasFound )
    
            if ( coLocated != null ) {
               var coLoMarker = createSpecialMarker( coLocated );
                if ( specialMarkers === null ) {
                    specialMarkers = new Array( coLoMarker );
                }
                else {
                    specialMarkers.push( coLoMarker );
                }
    
                i += --j;
                continue;
            }
    
            var point = new GLatLng(gl_list[i].Latitude,gl_list[i].Longitude);
            description = "Visited place : "+gl_list[i].nome +
                            " on : " + gl_list[i].data;
            map.addOverlay( createMarker( point, i + 1, description ) );
        }
    }
    

    The idea is to produce a single marker and let the InfoWindow convey the multiple pieces of information about the location that are important, ending up with something that looks like this:

    enter image description here

    Now I haven’t run this actual code, but it is based on code that runs every day. This is more intended to give you a fairly detailed look at the approach and share a body of code that should get you pretty darn close to a usable solution, with the understanding that it may need a little tweaking and debugging.

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
We're building an app, our first using Rails 3, and we're having to build

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.