更新时间:2023-12-01 10:40:16
MAX_ZINDEX
$是常量,而不是标记的属性。
相关的MarkerOption是 zIndex
:
var marker = new google.maps.Marker({
map:map,
position:latlng,
title:'pk:'+ name,
zIndex:zInd,
icon:image
});
这会将标记的 zIndex
属性设置为你已经计算出的价值,比API的最大值多一个。
Can somebody help me put the current location in front of all others? I have read about MAX_ZINDEX and setZindex() but I cannot understand it. This is my code:
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);
MAX_ZINDEX
is a constant, not an attribute of a marker.
The relevant MarkerOption is zIndex
:
var marker = new google.maps.Marker({
map: map,
position: latlng,
title:'pk:'+name,
zIndex: zInd,
icon: image
});
This sets the marker's zIndex
attribute to the value you have calculated, which is one more than the API's maximum value.