如何在同一个地方展示多个标记 [英] How to show more than one marker on same place

查看:120
本文介绍了如何在同一个地方展示多个标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi

I am using GoogleMap. When I have two or more markers on the exact same spot, The API only displays 1 marker - the top one. But somehow I want to show all the markers as each one will be opening distinct popup. I have searched found few solutions but none are seem to be working Anybody had similar issue and would pls share a solution??





我尝试过:



for(var i = filtered.length - 1; i> = 0; i--){

var item = records [filtered [i]];

chosenRecords + =(i == filtered.length - 1)? item.Id:,+ item.Id;



if(filtered.length< = 30000){

var marker = new google.maps.Marker({

删除:new google.maps.LatLng(item.lat,item.lng),

icon:icon,

标题:'点击我',

地图:地图,

id:item.Id,

infoWindowIndex:i

});

var infoWindow = new google.maps.InfoWindow({

删除:'abc here'

});

google.maps.event.addListener(marker,'click',function(event){

// if(infowindows){

// infowindows.close();

//}

infowindows [this.infoWindowIndex] .open(map,this);

} );

infowindows.push(infoWindow);

profileMarkers.push(marker);

}



What I have tried:

for (var i = filtered.length - 1; i >= 0; i--) {
var item = records[filtered[i]];
chosenRecords += (i == filtered.length - 1) ? item.Id : "," + item.Id;

if (filtered.length <= 30000) {
var marker = new google.maps.Marker({
removed: new google.maps.LatLng(item.lat, item.lng),
icon: icon,
title: 'Click me',
map: map,
id: item.Id,
infoWindowIndex: i
});
var infoWindow = new google.maps.InfoWindow({
removed: 'abc here'
});
google.maps.event.addListener(marker, 'click', function (event) {
//if (infowindows) {
// infowindows.close();
//}
infowindows[this.infoWindowIndex].open(map, this);
});
infowindows.push(infoWindow);
profileMarkers.push(marker);
}

推荐答案

以下是解决方案:

Here is the solution:
for (var i = 0; i < filtered.length; i++) {
                var item = records[filtered[i]];
                chosenRecords += "," + item.lat ;
                chosenRecords1 += "," + item.lng;
                dup = item.cnt;
                recordCont += item.cnt;
                if (filtered.length <= 30000) {                    
                    if (dup == 1) {
                        dup = '';
                    }
                    var img;
                    if (dup > 5) {
                        img = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + dup + '|a15ecb|FFFFFF';
                    }
                    else {
                        img = ((item.status == "RES") ? 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + dup + '|6abf24|FFFFFF' : (item.status == "NON") ? 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + dup + '|0061e2|FFFFFF' : (item.status == "OCP") ? 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + dup + '|e27500|FFFFFF' : (item.status == "DEC") ? 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + dup + '|eed100|FFFFFF' : (item.status == "???") ? 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + dup + '|FF0000|FFFFFF' : 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=' + dup + '|FF0000|FFFFFF');
                    }
                    var Mrkr_txt = item.status;
                    if (dup > 1) {
                        Mrkr_txt = 'Multiple Properties'
                    }
                  //  var lb = ''+dup+''
                    var marker = new google.maps.Marker({
                         position: new google.maps.LatLng(item.lat, item.lng),
                       //  icon: ((item.status == "RES") ? markerIcon1 : (item.status == "NON") ? markerIcon2 : (item.status == "OCP") ? markerIcon3 : (item.status == "DEC") ? markerIcon4 : (item.status == "???") ? markerIcon5 : markerIcon5),                       
                        //label: lb,
                         icon: img,
                        title: Mrkr_txt,
                        map: map,                       
                    });


这篇关于如何在同一个地方展示多个标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆