【发布时间】:2018-10-06 07:18:34
【问题描述】:
我有一张地图,上面有许多标记。由于它的设置方式,一个标记将始终与地图的中心重合。我想在该标记上向所有其他人显示不同的图标。
标记和它们对应的信息框是用这个函数定义的:
function createMarker(latlng, html, summary, photo1, photo2, thisLatlng) {
var contentString = "<div style='min-height:150px'>" + photo1 + "<img src='/images/" + photo2 + "' width='225' height='150' align='left' style='margin-right:8px;border:none'></a><span class='title'>" + html +"</span><br>" + summary + "</div>";
var marker = new google.maps.Marker({
map: map,
position: latlng,
icon: thisicon,
zIndex: Math.round(latlng.lat()*-100000)<<5
});
google.maps.event.addListener(marker, 'mouseover', function() {
ib.close(map, marker);
boxText.innerHTML = contentString;
ib.open(map, marker);
});
google.maps.event.addListener(map, 'click', function() {
ib.close(map, marker);
});
gmarkers.push(marker);
}
“latlng”是每个标记不同的纬度/经度。 "thisLatlng" 是地图的中心和一个特定标记的纬度/经度。
我的意图是使用这样的东西来确定要使用的正确图标:
if(latlng===thisLatlng){
var thisicon = icon1;
}else{
var thisicon = icon2;
}
但是它不起作用,因为“if”总是返回 false。我试过了
if(latlng===thisLatlng){
和
if(latlng==thisLatlng){
我也试过用 != 和 !== 反过来,但它们总是返回 false。 我检查了这两个值是否相等,将它们一个打印在另一个之上,它们看起来完全一样(应该是)。
我一定是做错了什么,但是什么?
【问题讨论】:
标签: google-maps if-statement google-maps-api-3