Как не позволить гугл карте группировать адреса вместе? - PullRequest
1 голос
/ 22 марта 2012

Я использую Google Map API для отображения адресов на карте с маркерами, проблема, с которой я сталкиваюсь, в маркере, я показываю ссылку, чтобы перейти на страницу профиля человека, который есть на карте, но еслисуществует более 1 человека по одному и тому же адресу, после чего Google группирует эти адреса и не показывает ссылку. Можно ли как-то остановить группировку адресов?Любая помощь будет оценена. Спасибо

<code><pre>
<script type="text/javascript">
var global =0;
//<![CDATA[
if (GBrowserIsCompatible()) {
  var side_bar_html = "";
  var gmarkers = [];
  var htmls = [];
  var i = 0;

  var allIcon = new GIcon();
  allIcon.image = "images/icons/<?php echo $map_category; ?>-all.png";
  allIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
  allIcon.iconSize = new GSize(35, 29);
  allIcon.shadowSize = new GSize(37, 34);
  allIcon.iconAnchor = new GPoint(9, 34);
  allIcon.infoWindowAnchor = new GPoint(9, 2);
  allIcon.infoShadowAnchor = new GPoint(18, 25);
  allIcon.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
  allIcon.printImage = "coldmarkerie.gif";
  allIcon.mozPrintImage = "coldmarkerff.gif";

  // An array of GIcons, to make the selection easier
  var icons = [];
  icons[0] = allIcon;
  icons[1] = planIcon;
  icons[2] = specialIcon;

  var clusterIcon = new GIcon();
  clusterIcon.image = 'images/icons/<?php echo $map_category; ?>-all.png';
  clusterIcon.iconSize = new GSize( 30, 51 );
  clusterIcon.shadowSize = new GSize( 56, 51 );
  clusterIcon.iconAnchor = new GPoint( 13, 34 );
  clusterIcon.infoWindowAnchor = new GPoint( 13, 3 );
  clusterIcon.infoShadowAnchor = new GPoint( 27, 37 );


  // A function to create the marker and set up the event window
  function createMarker(point,name,html,cat,id) {
    var marker = new GMarker(point,icons[cat]);
    GEvent.addListener(marker, "click", function() {
    rating_html = CallRating(<?php echo $page_id; ?>,id);
    rating_html = decodeURI(rating_html);
    marker.openInfoWindowHtml(html);        
    document.getElementById("rating_html_"+id+"").innerHTML=rating_html;
    });
    GEvent.addListener(marker, "dragstart", function() {
      map.closeInfoWindow();
    });
    // save the info we need to use later for the side_bar
    gmarkers[i] = marker;
    htmls[i] = html;
    // add a line to the side_bar html
    if(i%2==0)
    {
        var sclass="even";
    }
    else
    {
        var sclass="odd";
    }
    side_bar_html += '<li class="'+sclass+'"><a href="javascript:myclick(' + i + ',' + id + ')" class="map_data mapdata-list">' + name + '<\/a></li>';
    global=i;
    i++;
    return marker;
  }

  // This function picks up the click and opens the corresponding info window
  function myclick(i,id) {
    rating_html = CallRating(<?php echo $page_id; ?>,id);
    rating_html = decodeURI(rating_html);
    gmarkers[i].openInfoWindowHtml(htmls[i]);           
    document.getElementById("rating_html_"+id+"").innerHTML=rating_html;
  }


  // create the map
  var map = new GMap(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  //map.setMapType(G_SATELLITE_MAP);
  map.setCenter(new GLatLng(<?php echo $emp_info['emp_latitude']; ?>, <?php echo $emp_info['emp_longitude']; ?>), 8);
  // create the clusterer
  var clusterer = new Clusterer(map);

  // set the clusterer parameters if you dont like the defaults
  clusterer.icon = clusterIcon;      
  clusterer.maxVisibleMarkers = 100;
  clusterer.gridSize = 5;
  clusterer.minMarkersPerClusterer = 5;
  clusterer.maxLinesPerInfoBox = 6;

  var rating_html="";   
  // Read the data 
  var request = GXmlHttp.create();
  request.open("GET", "xml/<?php echo $org_id.'/emp/'.$emp_id.'/'.$map_category; ?>.xml", true);
  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      var xmlDoc = GXml.parse(request.responseText);
      // obtain the array of markers and loop through it
      var markers = xmlDoc.documentElement.getElementsByTagName("marker");
      var i = 0;
      for (i = 0; i < markers.length; i++) {
        // obtain the attribues of each marker
        var lat = parseFloat(markers[i].getAttribute("lat"));
        var lng = parseFloat(markers[i].getAttribute("lng"));
        var point = new GPoint(lng,lat);
        var town = markers[i].getAttribute("town");
        var name = markers[i].getAttribute("name");
        var id = markers[i].getAttribute("id");
        var cat = markers[i].getAttribute("cat");
        var marker = createMarker(point,name,"<a href='<?php echo $url;?>="+id+"' target='_blank' class='map_data'>"+name+"</a><br>"+town+"<div id='rating_html_"+id+"'></div>",cat,id);
        // create clusterer object
        clusterer.AddMarker(marker,town);
      }
      // put the assembled side_bar_html contents into the side_bar div
      if(side_bar_html=="")
      {
        document.getElementById("list_html").innerHTML = "<li>No data found! Please try again.</li>";
      } 
      else
      {
          document.getElementById("list_html").innerHTML = side_bar_html; 
          gmarkers[global].openInfoWindowHtml(htmls[global]);
          map.closeInfoWindow();
      }   
      // Clear the "please wait" message
    }
  }
  request.send(null);
}

else {
  alert("Sorry, the Google Maps API is not compatible with this browser");
}

//]]>
</script>

Ответы [ 2 ]

0 голосов
/ 22 апреля 2012

Хорошо, что Google показывает все относительные адреса вместе, в противном случае маркеры будут скрыты друг другом, и вы не сможете увидеть даже, сколько маркеров в одном месте.

0 голосов
/ 22 марта 2012

Если вы установите несколько маркеров для одного point, они всегда будут перекрываться.Будет интересно посмотреть, сможет ли кто-нибудь вам помочь.Я бы посоветовал, когда более одного человека попадают под одно место / маркер, укажите свои данные / ссылки на infoWindow.Не пытайтесь показывать несколько маркеров для одной и той же точки.И если вы достаточно отчаянны, чтобы показывать несколько маркеров, просто измените размер значков маркеров, чтобы они были видны пользователю, даже если они перекрываются.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...