我需要在Redis中存储纬度和经度。然后,我需要获取半径5公里以下的所有地理位置。为此,我使用下面的代码。
@Autowired
RedisTemplate redisTemplate;
GeoOperations<String, String> geoOperations;
@GetMapping("/test")
public ResponseEntity<Object> demoMethod(@RequestParam("distance") int distance) {
geoOperations=redisTemplate.opsForGeo();
geoOperations.add("Sicily", new Point(6.986786, 81.057408), "Dewala Veediya");
geoOperations.add("Sicily", new Point(6.984505, 81.058229), "Bank Road");
geoOperations.add("Sicily", new Point(6.990438, 81.056829), "Palermo");
geoOperations.add("Sicily", new Point(6.990703, 81.052492), "Vishaka");
geoOperations.add("Sicily", new Point(6.990703, 81.052492), "Vishaka");
geoOperations.add("Sicily", new Point(6.955504, 81.031509), "Haliela");
geoOperations.add("Sicily", new Point(6.931982, 79.846692), "colombo");
Circle circle = new Circle(new Point(6.990438, 81.056829),new Distance(distance, DistanceUnit.KILOMETERS));
GeoResults<GeoLocation<String>> result = geoOperations.radius("Sicily", circle);
return sendResponse(result);
}
响应为
{
"averageDistance": {
"value": 0,
"metric": "NEUTRAL"
},
"content": [
{
"content": {
"name": "Haliela",
"point": null
},
"distance": {
"value": 0,
"metric": "NEUTRAL"
}
},
{
"content": {
"name": "Bank Road",
"point": null
},
"distance": {
"value": 0,
"metric": "NEUTRAL"
}
},
{
"content": {
"name": "Dewala Veediya",
"point": null
},
"distance": {
"value": 0,
"metric": "NEUTRAL"
}
},
{
"content": {
"name": "Vishaka",
"point": null
},
"distance": {
"value": 0,
"metric": "NEUTRAL"
}
},
{
"content": {
"name": "Palermo",
"point": null
},
"distance": {
"value": 0,
"metric": "NEUTRAL"
}
}
]
}
我将经度和纬度分别作为X和Y点。为什么距离和点的值等于0。