好的,现在有这么一个需求。你所开发的应用的数据库中有全市所有饭店的经纬度坐标,现在你在某地定位了一个坐标,应用如何给你找出最近的饭店。多维空间搜索,使用RTree。这里只推荐已有的实现了RTree的jar包。
maven项目,可下载jar包,并且这是一个简单的例子:https://github.com/aled/jsi-examples
在线API:http://jsi.sourceforge.net/apidocs/index.html
下面附上自己很low的测试代码:
net.sf.jsi.examples;
gnu.trove.procedure.TIntProcedure;
net.sf.jsi.Point;
net.sf.jsi.Rectangle;
net.sf.jsi.SpatialIndex;
net.sf.jsi.rtree.RTree;
TestRTree {
run() {
Point point = Point(, );
Rectangle[] rectangle = Rectangle[];
rectangle[] = Rectangle(, , , );
rectangle[] = Rectangle(, , , );
rectangle[] = Rectangle(-, -, -, -);
rectangle[] = Rectangle(-, -, -, -);
SpatialIndex si = RTree();
si.init();
(i = ; i < rectangle.; i++) {
si.add(rectangle[i], i);
}
si.nearestN(point, TIntProcedure() {
execute(i) {
System..println(+ i + + [i] + + [i].distance());
;
}
}, , Float.);
}
main(String[] args) {
TestRTree().run();
}
}
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。