【问题标题】:Multiple google markers on the same place同一个地方有多个谷歌标记
【发布时间】:2012-09-04 04:13:15
【问题描述】:

我正在尝试使用带有标记的谷歌地图。我在地图中放置标记没有任何问题,但是当我必须在同一个地方标记时,如何让标记像谷歌地球一样分裂?像这样:Example

谢谢!

【问题讨论】:

    标签: google-maps google-maps-markers


    【解决方案1】:

    我不明白您要完成什么,但是...

    您是否已经检查过诸如this onegoogle semi-official 之类的标记聚类算法?

    【讨论】:

    • 嗨,谢谢你的回答,是的,我已经检查了其他人,但不是我想要的,当它们处于完全相同的位置时,我如何才能看到标记?谷歌地球有什么选择吗?
    【解决方案2】:
    //Here is my attempt... a Archimedes spiraling out of the markers:
    
    // calc a spiraling out position based on marker count at that location
    // this function is very tweeky
    function spiral_coords(lat_long, i) {
        i = (i == 1)? 0: i+1;
        var r = i * 0.002;
        // .8 is a fudge number to adjust to real appearance on the map
        return [lat_long[0] + (r * .8 * Math.sin(.5 * (i + 2))), lat_long[1] + (r * Math.cos(.5 * (i + 2)))];
    }
    
    // this is from a fusion table query... but your source could be anything
    // I take the coords and check against a hash count of them and calc out the spiral position
    function data_handler(d) {
        var map = $("#map")[0];
        map.markers = [];
    
        var rows = d.rows;
        var fields = d.columns;
        var index = {};
        for (var i in fields) {
            index[fields[i]] = i;
        }
        var location_count = {};
    
        for (var i in rows) {
            var row = rows[i];
            var location = row[index["Location"]];
            var lat_long = location.split(" ");
            lat_long[0] = parseFloat(lat_long[0]);
            lat_long[1] = parseFloat(lat_long[1]);
                    // here are the active ingredients
            if(!(location in location_count)) {
                location_count[location] = 0;
            }
            location_count[location]++;
            lat_long = spiral_coords(lat_long, location_count[location]);
            var marker = new google.maps.Marker({
                position: new google.maps.LatLng(lat_long[0], lat_long[1]),
                map: map.map
            });
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-27
      • 2011-12-25
      • 2015-07-05
      • 1970-01-01
      • 2012-07-19
      • 2010-10-11
      • 1970-01-01
      相关资源
      最近更新 更多