我在我的应用中使用Google Maps,并且有一个填充有纬度/经度数据的网站服务器。我想在地图上标记它们,但如果它们相互之间距离在一定像素范围内,我还想将它们聚合在一起。
我想,如果我从数据库中检索出所有点,我应该能够执行类似以下的操作(伪代码):
clusters[];
while(count(points)) {
cluster[];
point = points.pop();
boundingbox = pixelsToBB(point, pixeldistance, zoomlevel);
query = "select * from database where lat > boundingbox.minlat
and lat < boundingbox.maxlat and lng > boundingbox.minlng
and lng < boundingbox.maxlng";
for (result in executedquery) {
cluster[] += result;
points.remove(result);
}
clusters[] += cluster;
}
pixelsToBB(point, distance, zoomlevel) {
center = convertXY(point, zoomlevel);
maxlng = convertToLng(center.X, distance, zoomlevel);
minlng = convertToLng(center.X, -distance, zoomlevel);
minlat = convertToLat(center.Y, -distance, zoomlevel);
maxlat = convertToLat(center.Y, distance, zoomlevel);
return boundingbox(maxlng, maxlat, minlng, minlat);
}
我的pixelsToBB函数需要如何处理缩放级别?或者说,我的convertToXY、convertToLng和convertToLat函数需要如何处理?我是否正确地考虑了这个问题,还是有更好的方法可以实现?我甚至不确定要搜索什么,如果已经有人问过,请原谅我。