开发者

Multiple google markers on the same place

开发者 https://www.devze.com 2023-02-01 08:38 出处:网络
i\'m trying touse google maps with markers. i do not have any problems with the placement of markers in the map, but how can i get the markers 开发者_如何转开发to split like google earth when i have t

i'm trying to use google maps with markers. i do not have any problems with the placement of markers in the map, but how can i get the markers 开发者_如何转开发to split like google earth when i have to markers in the same place? like this : Example

Thanks !


I didn't understand what you're trying to accomplish, but ...

Did you already check a marker clustering algorithm like this one or the google semi-official ?


//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
        });
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号