首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用Redis geo 存取经纬度不一致导致距离计算有误差?

使用Redis geo 存取经纬度不一致导致距离计算有误差?

提问于 2023-12-28 15:15:50
回答 1关注 0查看 173

使用如下代码存入坐标A经纬度

代码语言:javascript
复制
// x = 113.751337, y = 23.021206
stringRedisTemplate.opsForGeo().geoAdd(key, new Point(x, y), member);

使用如下代码获取指定距离内坐标列表

代码语言:javascript
复制
// longitude = x = 113.751337, latitude = y = 23.021206
Circle circle = new Circle(new Point(longitude, latitude), new Distance(6000000L, RedisGeoCommands.DistanceUnit.METERS));
RedisGeoCommands.GeoRadiusCommandArgs args = RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs()
                .includeDistance().includeCoordinates().sortAscending();
GeoResults<RedisGeoCommands.GeoLocation<String>> geoResults = stringRedisTemplate.opsForGeo().geoRadius(key, circle, args);

期望结果是距离为0, 但是结果是0.2091, 打断点查看最后一行代码, 从Redis取出的坐标及位置数据, 发现存入的坐标A经纬度为

Point [x=113.751339, y=23.021206]

与存入数据有差异, 应该也不是四舍五入之类的原因.

在尝试多存入几个坐标, 发现存取数据还是不一致

如:

存入 : -> 输出

113.847252, 22.906628 -> Point [x=113.847249, y=22.906629]

114.000553, 22.981234 -> Point [x=114.000554, y=22.981233]

113.63426, 22.852197 -> Point [x=113.634261, y=22.852198]

第一次使用Redis geo , 希望社区大佬帮看看

补充: 从Redis取出对应的坐标的score值到http://geohash.org/解析, 得到的坐标值就是与存入时不同, 如存入(116.983469,36.667), 命令: GEOHASH key member 得到的值为wwe0w50b8r0, 解析出来的坐标是(116.98346,36.66699)

相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档