hunk
V2EX  ›  Java

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

  •  
  •   hunk · Sep 10, 2023 · 1532 views
    This topic created in 974 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   ·   5104 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 09:44 · PVG 17:44 · LAX 02:44 · JFK 05:44
    ♥ Do have faith in what you're doing.