org.springframework.data.geo.Metric Java Examples
The following examples show how to use
org.springframework.data.geo.Metric.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeoPredicate.java From spring-data-hazelcast with Apache License 2.0 | 6 votes |
/** * This method users Haversine formula to calculate the distance between two points * Formula is explained here - https://www.movable-type.co.uk/scripts/gis-faq-5.1.html * Sample Java code is here - https://rosettacode.org/wiki/Haversine_formula#Java * @param lat1 - Latitude of first point. * @param lng1 - Longitude of first point. * @param lat2 - Latitude of second point. * @param lng2 - Longitude of second point. * @param metric - metric to specify where its KILOMETERS, MILES or NEUTRAL * @return */ private double calculateDistance(double lat1, double lng1, double lat2, double lng2, Metric metric) { if ((lat1 == lat2) && (lng1 == lng2)) { return 0; } else { double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lng2 - lng1); double lat1Radians = Math.toRadians(lat1); double lat2Radians = Math.toRadians(lat2); double a = Math.pow(Math.sin(dLat / 2), 2) + Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1Radians) * Math.cos(lat2Radians); double c = 2 * Math.asin(Math.sqrt(a)); double dist = R * c; if (Metrics.MILES.equals(metric)) { dist = dist * KM_TO_MILES; } else if (Metrics.NEUTRAL.equals(metric)) { dist = dist * KM_TO_NEUTRAL; } return dist; } }
Example #2
Source File: TracingRedisConnection.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) { return helper.doInScope(RedisCommand.GEODIST, key, () -> connection.geoDist(key, member1, member2, metric)); }
Example #3
Source File: TracingRedisConnection.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) { return helper.doInScope(RedisCommand.GEODIST, key, () -> connection.geoDist(key, member1, member2, metric)); }
Example #4
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 4 votes |
@Override public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) { return read(key, DoubleCodec.INSTANCE, new RedisCommand<Distance>("GEODIST", new DistanceConvertor(metric)), key, member1, member2, metric.getAbbreviation()); }
Example #5
Source File: DistanceConvertor.java From redisson with Apache License 2.0 | 4 votes |
public DistanceConvertor(Metric metric) { super(); this.metric = metric; }
Example #6
Source File: DistanceConvertor.java From redisson with Apache License 2.0 | 4 votes |
public DistanceConvertor(Metric metric) { super(); this.metric = metric; }
Example #7
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 4 votes |
@Override public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) { return read(key, DoubleCodec.INSTANCE, new RedisCommand<Distance>("GEODIST", new DistanceConvertor(metric)), key, member1, member2, metric.getAbbreviation()); }
Example #8
Source File: DistanceConvertor.java From redisson with Apache License 2.0 | 4 votes |
public DistanceConvertor(Metric metric) { super(); this.metric = metric; }
Example #9
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 4 votes |
@Override public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) { return read(key, DoubleCodec.INSTANCE, new RedisCommand<Distance>("GEODIST", new DistanceConvertor(metric)), key, member1, member2, metric.getAbbreviation()); }
Example #10
Source File: DistanceConvertor.java From redisson with Apache License 2.0 | 4 votes |
public DistanceConvertor(Metric metric) { super(); this.metric = metric; }
Example #11
Source File: RedissonConnection.java From redisson with Apache License 2.0 | 4 votes |
@Override public Distance geoDist(byte[] key, byte[] member1, byte[] member2, Metric metric) { return read(key, DoubleCodec.INSTANCE, new RedisCommand<Distance>("GEODIST", new DistanceConvertor(metric)), key, member1, member2, metric.getAbbreviation()); }
Example #12
Source File: DistanceConvertor.java From redisson with Apache License 2.0 | 4 votes |
public DistanceConvertor(Metric metric) { super(); this.metric = metric; }
Example #13
Source File: DistanceConvertor.java From redisson with Apache License 2.0 | 4 votes |
public DistanceConvertor(Metric metric) { super(); this.metric = metric; }