【问题标题】:Put marker from Google Maps v3 in front of all others将 Google Maps v3 中的标记放在所有其他标记的前面
【发布时间】:2012-06-19 13:35:01
【问题描述】:

有人可以帮我把当前位置放在所有其他人的前面吗?我已经阅读了有关 MAX_ZINDEX 和 setZindex() 的信息,但我无法理解。这是我的代码:

var latlng = new google.maps.LatLng(lat,lng);
var image = "";
var currentplace = "Ohla Hotel";
var zInd = "";
if( name == currentplace ) {
    image = "../img/hotel_icon.png";
}
else {
    image = "../img/home_icon.png";
}
//alert();
var maxZindex = google.maps.Marker.MAX_ZINDEX;
if( name == currentplace ) {
    zInd = (maxZindex + 1);
}
var locationDescription = this.locationDescription;
var marker = new google.maps.Marker({
    map: map,
    position: latlng,
    title:'pk:'+name,
    MAX_ZINDEX: zInd,
    icon: image
});
bounds.extend(latlng);
setMarker(map, marker, name, locationDescription);

【问题讨论】:

    标签: google-maps-api-3 google-maps-markers


    【解决方案1】:

    MAX_ZINDEX是一个常数,不是标记的属性。

    相关的 MarkerOption 是zIndex:

    var marker = new google.maps.Marker({
        map: map,
        position: latlng,
        title:'pk:'+name,
        zIndex: zInd,
        icon: image
    });
    

    这会将标记的zIndex 属性设置为您计算的值,该值比 API 的最大值大一。

    【讨论】:

      【解决方案2】:

      您的大部分代码都有意义,但您对 MarkerOptionsapi-doc 对象的定义没有意义。尝试将您的标记创建代码更改为:

      var marker = new google.maps.Marker({
          map: map,
          position: latlng,
          title:'pk:'+name,
          zIndex: zInd,
          icon: image
      });
      

      由于您已将zInd 的值设置为高于google.maps.Marker.MAX_ZINDEX,因此进行此更改应将标记置于zIndex 中更高的位置,从而高于地图上的其他标记。

      【讨论】:

      • 我已经尝试过了,'zIndex: 999',但它根本不工作给我一个错误位置,但如果我这样做 'google.maps.event.addListener(marker, 'mouseover' , function() { marker.setZIndex(9999); ib.close(); //ib.setContent($infoWindowContent[0]); ib.open(map, marker);´ 它只在悬停时工作我需要它当前位置在前面。
      • 当您尝试使用MarkerOptions.zIndex 属性时遇到什么错误?
      • 地图不在 lat 和 lng
      • 你的意思是标记不在纬度和经度上吗?地图?
      • 我无法理解您的英语,也无法准确找出问题所在。我回复了您在问题中提交的代码,但是您在我的答案中说您已经尝试过的代码。如果你想用你当前的代码和你尝试过的细节来更新你的问题,我会尽力提供帮助。否则,我将不得不承认我无法弄清楚你在说什么。也许您可以提供指向您页面的链接或设置 jsFiddle?
      猜你喜欢
      • 1970-01-01
      • 2013-05-24
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 2010-12-23
      • 1970-01-01
      • 2010-12-05
      相关资源
      最近更新 更多