V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xlzyxxn
V2EX  ›  程序员

Java 的 GEO 问题

  •  
  •   xlzyxxn · 16 天前 · 1262 次点击

    比如有个数据中心列表,怎么找到距离用户输入的省市最近的数据中心,或者得到两地的距离; java 有这样的库或者有什么开源服务能做到?

    10 条回复    2024-05-16 22:36:32 +08:00
    xlzyxxn
        1
    xlzyxxn  
    OP
       16 天前
    有没有 V 友用过很好用的?
    vagusss
        2
    vagusss  
       16 天前
    redis, es
    ZField
        3
    ZField  
       16 天前
    数量少,并发低直接算。
    或者转成 GeoHash ,找到最近的再算距离,工具的话 github 上搜一搜有一堆。
    wu00
        4
    wu00  
       16 天前
    数据库都有”point“字段类型的吧
    gadfly3173
        5
    gadfly3173  
       16 天前 via Android
    用数据库就是楼上说的,或者参考美团的 https://tech.meituan.com/2014/09/05/lucene-distance.html
    tairan2006
        6
    tairan2006  
       16 天前
    redis, mysql, pg 都有的
    RicardoY
        7
    RicardoY  
       16 天前
    这个是典型的附近搜场景,直接用 JTS 就行了
    dif
        8
    dif  
       16 天前
    一般用 redis 。
    codingmiao
        9
    codingmiao  
       16 天前
    几种我自己用的方案:
    数据量很小时,直接 jts 在内存里遍历判断。
    数据量大时,可以考虑在内存里搞一棵 Rtree https://www.khelekore.org/prtree/index.shtml
    我自己撸了个变种,把 Rtree 从内存放倒图数据库 https://github.com/codingmiao/neo4j-rtree?tab=readme-ov-file#%E6%9C%80%E9%82%BB%E8%BF%91%E6%90%9C%E7%B4%A2
    也可以给 pg 装个 postgis 插件来处理。
    redis 用 geohash 来实现空间索引,优点是简单,但 geohash 的不连续性会导致某些坐标的查询性能骤降有点烦。
    codingmiao
        10
    codingmiao  
       16 天前
    哦对了,mysql 的 geometry 就是个玩具,wgs84 的坐标 x y 非要反着存,linestring 会莫名其妙的不走索引等问题,非常不推荐使用
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   924 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 21:00 · PVG 05:00 · LAX 14:00 · JFK 17:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.