php - 如何不让谷歌地图组地址在一起?

标签 php javascript jquery google-maps

我正在使用谷歌地图API在带有标记的 map 上显示地址,我遇到的问题是,在标记中,我显示了一个链接到 map 中人员的个人资料页面,但是如果同一地址上存在超过 1 个人,然后 google 将这些地址分组,但不显示链接,有什么方法可以停止地址分组吗? 任何帮助将不胜感激。谢谢

<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>
</pre>

最佳答案

如果您为单个放置多个标记,这些标记将始终重叠。看看是否有人可以帮助你会很有趣。我建议,当有多个人位于同一地点/标记下时,将他们的详细信息/链接放在 infoWindow 上。不要尝试为同一点显示多个标记。如果您非常渴望显示多个标记,那么只需更改标记图标的大小,以便即使重叠,用户也可以看到它们。

关于php - 如何不让谷歌地图组地址在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9816983/

相关文章:

php - Symfony2 安全,使用 sha512,不工作。收到错误的凭据消息

javascript - 从 ASP.NET 中的按钮播放声音

javascript - MongoDB 查询可以工作,但不能与 Mongoose 一起使用

javascript - 无法在 JQUERY 中重置()

jquery - Chrome 在刷新后更改样式并在我右键单击以检查它时更正它

javascript - 使用 php 从网络服务器读取时,JSON 文件返回 null。

php - 神秘的 GC 缓存条目是什么意思

php - Blueimp 文件多重上传到 Mysql

javascript - jQuery 用户界面 : Autocomplete - How do I search multiple values within an array?

php - 在 codeigniter 中使用 AJAX 上传文件时出错