redis中的geo功能能否直接使用高德地图gcj02的坐标?

可以在Redis GEO函数中直接使用高德坐标,即GCJ-02坐标。


测试
  1. 我们使用redis geo添加13个坐标。即:
        addGym("pku", 116.310845, 39.992912);//北大
        addGym("tingshua", 116.326724, 40.0033);//清华
        addGym("linda", 116.347495, 40.005602);//凌达
        addGym("nongda", 116.357366, 40.004813);//农大
        addGym("yuyanda", 116.346551, 39.995016);//语言大
        addGym("dida", 116.348954, 39.991465);//地大
        addGym("keda", 116.359254, 39.99015);//北科大
        addGym("beihang", 116.34698, 39.981666);//北航
        addGym("renda", 116.312991, 39.970485);//人大
        addGym("beishi", 116.365863, 39.961538);//北师
        addGym("beili", 116.314965, 39.959894);//北理
        addGym("minda", 116.32063, 39.950354);//民大
        addGym("beijiao", 116.342345, 39.952064);//北京交大
  1. 我们使用georadius功能以北京大学坐标为例进行测试
    #####距离为3公里,返回:

    {"id":"pku","latitude":39.99291283048765,"longitude":116.31084233522415}
    {"id":"tingshua","latitude":40.003300117798624,"longitude":116.32672637701035}
    {"id":"renda","latitude":39.970485617669816,"longitude":116.3129934668541}

    #####距离为5公里,返回:

    {"id":"beili","latitude":39.95989301794494,"longitude":116.31496757268906}
    {"id":"renda","latitude":39.970485617669816,"longitude":116.3129934668541}
    {"id":"beihang","latitude":39.98166627270366,"longitude":116.34698241949081}
    {"id":"dida","latitude":39.991465504705666,"longitude":116.34895652532578}
    {"id":"keda","latitude":39.99014998442397,"longitude":116.35925620794296}
    {"id":"pku","latitude":39.99291283048765,"longitude":116.31084233522415}
    {"id":"tingshua","latitude":40.003300117798624,"longitude":116.32672637701035}
    {"id":"yuyanda","latitude":39.995016649049894,"longitude":116.34655326604843}
    {"id":"linda","latitude":40.005601644611296,"longitude":116.34749740362167}
    {"id":"nongda","latitude":40.00481334633074,"longitude":116.35736793279648}
    {"id":"minda","latitude":39.95035486222235,"longitude":116.32063239812851}

这些测试结果都是正确的

  1. 我们对使用高德地图坐标的两个点间的距离进行测试
两点使用redis geo测试的距离(高德坐标体系)/米使用高德地图中测距工具实际测出的距离/公里
北大清华1779.48631.8
北大人大2501.2242.5
北大北航3324.20533.3
北大农大4179.38994.1

结论

  1. redis geo使用高德坐标测试附近的距离正确。
  2. redis geo使用高德坐标,计算两点间距离正确。
因此可以认为高德地图坐标可以在redis geo中使用

(转自 https://wuwawuwa.cn )

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot提供了对Redis的集成支持,可以使用Spring Data Redis来操作Redis。要在Spring Boot使用RedisGEO功能,可以按照以下步骤进行操作: 1. 首先,确保在你的pom.xml(如果使用Maven)或build.gradle(如果使用Gradle)文件添加以下依赖项: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> ``` 2. 在application.properties或application.yml文件配置Redis连接信息: ```yaml spring.redis.host=your-redis-host spring.redis.port=your-redis-port ``` 3. 创建一个实体类来表示地理位置信息,可以使用Spring Data Redis提供的`@RedisHash`和`@Indexed`注解来定义实体和索引,例如: ```java @RedisHash("locations") public class Location { @Id private String id; private String name; private Point point; // 用于存储地理位置的Point对象 // 省略构造方法、Getter和Setter } ``` 4. 创建一个继承自`CrudRepository`的Repository接口,用于对地理位置实体进行CRUD操作。可以使用Spring Data Redis提供的`@GeoIndexed`注解来定义地理位置索引,例如: ```java public interface LocationRepository extends CrudRepository<Location, String> { @GeoIndexed List<Location> findByPointNear(Point point, Distance distance); } ``` 5. 在需要使用地理位置功能的地方注入`LocationRepository`,然后就可以使用该Repository进行地理位置的操作了。例如,可以使用`findByPointNear`方法查询给定地理位置附近的其他位置,例如: ```java @Autowired private LocationRepository locationRepository; public List<Location> findNearbyLocations(Point point, double distance) { Distance searchDistance = new Distance(distance, Metrics.KILOMETERS); return locationRepository.findByPointNear(point, searchDistance); } ``` 这样,你就可以在Spring Boot使用RedisGEO功能了。注意,以上只是一个简单的示例,实际使用可能需要根据自己的业务需求进行适当的调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值