1

I display cruise routes on a google map and mark each port with an infobox. Unfortunately these infoboxes regularly overlap. How can this be avoided?

I've already tried spiderfy but it's not suitable in this instance.

Changing the zoom level of the map is also not an option. The ideal would be a plugin or something similar that can recognize overlapping infoboxes at creation and rearrange them. However, I haven't been able to find something like this anywhere.

A second possibility would be to change the position via javascript, but given my lack of expertise with javascript & google maps, I haven't been able to achieve this. Nor have I found an example that I could hack.

Would appreciate some info/advice/pointers in the right direction.

Thanks MK

Here's my code:

function initialize() {
    var arrayMarkers = [];
    var idx = 0;
    var mapLatlng = new google.maps.LatLng(-27.6264198719, 146.9179666042);
    var mapOptions = { center: mapLatlng,
    zoom: 13, 
    mapTypeId: google.maps.MapTypeId.SATELLITE };
    var map = new google.maps.Map(document.getElementById("karte"), mapOptions);
    var bounds = new google.maps.LatLngBounds();

    arrayMarkers[idx] = [];
    arrayMarkers[idx]['breite'] = -33.859261813133;
    arrayMarkers[idx]['laenge'] = 151.200070381165;
    arrayMarkers[idx]['farbe'] = "http://new.kfb.localhost:8888/img/ico/button2_gruen.png";arrayMarkers[idx]['hafen'] = "Abfahrt Sydney";
    arrayMarkers[idx]['link'] = "Karte&#44; Wetter und<br>Landausfl&uuml;ge f&uuml;r<br><a href='hafen.php?hafen=528'>Sydney</a><br>Do, 07.02.13";idx++;
    arrayMarkers[idx] = [];

      .
      .
      . etc.

To add the markers and infoboxes to the map, I call this function:

function create_markers_v3(map, bounds, arrayMarkers) {

var latLng = [];
var img = [];
var marker = [];
var optionsPort = [];
var ib = [];
var infoWindow = [];

for (i = 0; i < arrayMarkers.length; i++)
{
    latLng[i] = new google.maps.LatLng(arrayMarkers[i]['breite'], arrayMarkers[i]['laenge']);
    bounds.extend(latLng[i]);
    map.fitBounds(bounds);
    img[i] = arrayMarkers[i]['farbe'];
    marker[i] = new google.maps.Marker(
    {
        position: latLng[i],
        map: map,
        icon: img[i]
    });
    optionsPort[i] = {
        content: arrayMarkers[i]['hafen'],
        disableAutoPan: false,
        pixelOffset: new google.maps.Size(3, -20),
        position: new google.maps.LatLng(arrayMarkers[i]['breite'], arrayMarkers[i]['laenge']),
        zIndex: null,
        boxStyle: { 
            opacity: 0.81,
            fontSize: "6pt",
            backgroundColor: "#ffffff",
            padding: "0 2px 1px 3px",
            lineHeight: "1em",
            border: "1px solid #333333"
        },
        closeBoxURL: "",
        isHidden: false,
        pane: "floatPane",
        enableEventPropagation: true
    };
    if (arrayMarkers[i]['hafen'].length > 0)
    {
        ib[i] = new InfoBox(optionsPort[i]);
        ib[i].open(map, marker[i]);
        arrayMarkers[i]['ib'] = ib[i];

        if (arrayMarkers[i]['link'].length > 0)
        {                   
            addInfoWindow(map, arrayMarkers[i], marker[i], i);
        }
    }
}
return arrayMarkers;

}

midnig
  • 183
  • 5
  • 16
  • What does your code currently look like? Are you asking about [InfoBoxes](http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html), [InfoWindows](https://developers.google.com/maps/documentation/javascript/reference#InfoWindow), or [Markers](https://developers.google.com/maps/documentation/javascript/reference#Marker)? – geocodezip Mar 04 '13 at 14:55
  • It's about infoboxes. I've added the code in the body of the question. – midnig Mar 04 '13 at 15:36
  • Perhaps you could provide an example that exhibits the behavior you are trying to address (with only one InfoBox, there is no problem). I don't think you are going to find an easy way to do this, your only option is to process through the InfoBoxes, add them, making sure new ones don't overlap the existing ones. I don't think any such code exists (but I could be wrong). What I have done, when using [InfoBoxes for map labels](http://www.geocodezip.com/ParkerPalmSprings.html) is hide them when they start to overlap. – geocodezip Mar 04 '13 at 23:53
  • Thanks for the input. In the absence of a plugin or library to take care of overlapping, I guess it'll have to be done manually. The problem here is to find the pixel position of the infoboxes. The offset from the latlng point is readily available, but I have no idea how to get the absolute pixel position on the map. – midnig Mar 05 '13 at 08:25
  • Did you found any soluntion.I also in great need for this.Plz let me know? – Somnath Kharat Jul 20 '16 at 13:32

0 Answers0