V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
hunk
V2EX  ›  Java

spring 中使用 redis 搜索附近位置总是返回为空

  •  
  •   hunk · Sep 10, 2023 · 1490 views
    This topic created in 960 days ago, the information mentioned may be changed or developed.

    Spring 加载时从数据库读取数据写入 redis ,使用命令行可以返回结果 geosearch project:locs fromlonlat 112.xx 32.xx BYRADIUS 200 km WITHDIST ASC

      1. "9"
    1. "1.3747"
      1. "11"
      2. "2.2997"
      1. "10"
      2. "2.4876"

    但在程序中始终结果为 0 ,请帮忙分析下是什么原因?

        String key = "project:locs";
    
        GeoResults<RedisGeoCommands.GeoLocation<String>> results = redisTemplate.opsForGeo().search(
                key,
                GeoReference.fromCoordinate(112.xx,32.xx),
                new Distance(5000000, Metrics.KILOMETERS),
                RedisGeoCommands.GeoSearchCommandArgs.newGeoSearchArgs().includeDistance().limit(100));
    
        List<GeoResult<RedisGeoCommands.GeoLocation<String>>> content = results.getContent();
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5041 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 434ms · UTC 05:38 · PVG 13:38 · LAX 22:38 · JFK 01:38
    ♥ Do have faith in what you're doing.