问题
I have a set of points (coordinates), and I can calculate de distance from each to all.
But I want to group the points that are near each other (lets say, less than 500m).
PointsCoords =[
["lat01, lng01", "P01"],
["lat02, lng02", "P02"],
["lat03, lng03", "P03"],
["lat04, lng04", "P04"],
["lat05, lng05", "P05"],
["lat06, lng06", "P06"],
["lat07, lng07", "P07"]
];
I make the calculations and I know now that for distance less than 500m I have the pairs:
varAllPairs = [
[P01, P03], //450m
[P02, P03], //200m
[P05, P06]] //350m
But, how do I group them like:
varClusterGroups = [P01,P02,P03], [P05,P06]
(I know that P01 to P02 is more than 500m, but for now its better than nothing... is there a better way to find a REAL cluster of points?)
How can I make the group (varClusterGroups) with javascript or jquery (or underscore)?
Or maybe a solution 2: Get all the coordinates and apply an algorithm that gives me the clustered groups
Tks
EDIT: I really don't know the right criteria, but what I need is to receive an alert when I have 2 or more points close enough (this is to detect when 2 or more vehicles are close enough [less than X m from each other], when they are not suppose to), so I don´t have a "center point" pre-defined. I just want to have the information that vehicles 01,03,04 and 05,07,08 and 09,15 are "grouped". It can be the possibility than one or more points belongs to other group, but I think that if two groups have common point it should be converted to one group.
来源:https://stackoverflow.com/questions/18696218/how-to-group-coordinates-by-distance