spring-projects / spring-data-redis

Provides support to increase developer productivity in Java when using Redis, a key-value store. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-redis/
Apache License 2.0
1.77k stars 1.17k forks source link

org.springframework.dao.InvalidDataAccessApiUsageException: ERR invalid longitude,latitude pair 13.756631,100.566006; [DATAREDIS-754] #1335

Closed spring-projects-issues closed 6 years ago

spring-projects-issues commented 6 years ago

Vinod Kumar Jagwani opened DATAREDIS-754 and commented

Hi, I am getting issue using springboot 1.5.9 rela and spring redis starter:

org.springframework.dao.InvalidDataAccessApiUsageException: ERR invalid longitude,latitude pair 13.756631,100.566006;

Can you help me to resolve this


No further details from DATAREDIS-754

spring-projects-issues commented 6 years ago

Christoph Strobl commented

please add more information. How do you use the api? Can you provide a code snippet so we can see what happens?

From the error msg provided I'd guess you mixed up lon and lat, assuming it should have been lat: 13,756... and lon: 100.566...

spring-projects-issues commented 6 years ago

Vinod Kumar Jagwani commented

Yes, sure,

I am adding list of latitude and longitude and want to find near by locations (from my input latitude, longitude )

when u add these values (13.756631,100.566015)

public List<CurrentGeoLocation> findNearByLocation(final Double latitude, final Double longitude) {
        redisTemplate.delete("geo");
        List<CurrentGeoLocation> geoLocationList = new ArrayList<>();
        final GeoOperations<String, CurrentGeoLocation> geoOpt = redisTemplate.opsForSet().getOperations().opsForGeo();
        for (CurrentGeoLocation currentGeoLocation : currentGeoLocationService.findAll()) {
            Point point = new Point(currentGeoLocation.getLatitude(), currentGeoLocation.getLongitude());
            geoOpt.geoAdd("geo", point, currentGeoLocation);
        }
        Point breakDownPoint = new Point(latitude, longitude);
        Circle circle = new Circle(breakDownPoint, new Distance(radius, RedisGeoCommands.DistanceUnit.KILOMETERS));
        final GeoResults<RedisGeoCommands.GeoLocation<CurrentGeoLocation>> result = geoOpt.geoRadius(
                GeoTrackingConstants.GEO_KEY, circle);
        List<GeoResult<RedisGeoCommands.GeoLocation<CurrentGeoLocation>>> locations = result.getContent();
        for (GeoResult<RedisGeoCommands.GeoLocation<CurrentGeoLocation>> location : locations) {
            if (location.getContent().getName() != null) {
                geoLocationList.add(location.getContent().getName());
            }
        }
        return geoLocationList;
spring-projects-issues commented 6 years ago

Mark Paluch commented

Fyi, Redis lon/lat limits are:

/* Limits from EPSG:900913 / EPSG:3785 / OSGEO:41001 */
#define GEO_LAT_MIN -85.05112878
#define GEO_LAT_MAX 85.05112878
#define GEO_LONG_MIN -180
#define GEO_LONG_MAX 180
spring-projects-issues commented 6 years ago

Christoph Strobl commented

The conversion from Point(x,y) to redis.clients.jedis.GeoCoordinate(lon,lat) is defined as x = longitude and y = latitude.

So flipping arguments should solve your problem.

@Test
public void somewhereInItaly() {

    // longitude is the X axis
    final Double lon = 13.583333D;
    final Double x = lon;

    // Latitude is the Y axis
    final Double lat = 37.316667;
    final Double y = lat;

    // actually: https://www.google.com/maps/place/37.31643+13.582560000000058/@37.31643,13.582560000000058,17z
    final Point arigento_XY = new Point(x, y);
    final Point arigento_LonLat = new Point(lon, lat);

    GeoCoordinate geo = JedisConverters.toGeoCoordinate(arigento_XY);

    Assertions.assertThat(geo.getLatitude()).isEqualTo(lat);
    Assertions.assertThat(geo.getLongitude()).isEqualTo(lon);

    Assertions.assertThat(JedisConverters.toGeoCoordinate(arigento_LonLat)).isEqualTo(geo);
}
spring-projects-issues commented 6 years ago

Vinod Kumar Jagwani commented

Hi Christoph Strobl,

Yes that was the issue, and now i am not getting this issue, thank you so much for your help. (y)