当前位置: 首页 > news >正文

网站的花费wordpress用不了了

网站的花费,wordpress用不了了,百度推广帮做网站,建网站原型图更多SpringBoot3内容请关注我的专栏#xff1a;《SpringBoot3》 期待您的点赞#x1f44d;收藏⭐评论✍ 重学SpringBoot3-集成Redis#xff08;十一#xff09;之地理位置数据存储 1. GEO 命令简介2. 项目环境配置2.1. 依赖引入2.2. Redis 配置 3. GEO 数据存储和查询实现3… 更多SpringBoot3内容请关注我的专栏《SpringBoot3》 期待您的点赞收藏⭐评论✍ 重学SpringBoot3-集成Redis十一之地理位置数据存储 1. GEO 命令简介2. 项目环境配置2.1. 依赖引入2.2. Redis 配置 3. GEO 数据存储和查询实现3.1. 服务层实现3.2. 控制层 4. 使用示例4.1. 添加城市位置信息4.2. 查询城市位置信息4.3. 计算两城市之间的距离4.4. 查询指定城市附近的其他城市 5. 总结 Redis 是一个强大的内存数据存储工具不仅可以用来缓存和存储传统数据还支持存储地理位置信息。通过 Redis 提供的 GEO 命令集开发者可以方便地进行地理位置的存储、查询和计算操作。本文将介绍如何通过 Spring Boot 3 与 Redis 集成来实现地理位置数据存储功能并进行相关的操作。 1. GEO 命令简介 Redis 的 GEO 命令主要用于存储经纬度和关联的数据并支持基于这些数据进行距离计算和范围查询。常用的 GEO 命令有 GEOADD添加地理位置。GEOPOS获取指定成员的地理位置经纬度。GEODIST计算两个地理位置之间的距离。GEORADIUS以给定的经纬度为中心查询某个范围内的地理位置。GEORADIUSBYMEMBER以给定的成员位置为中心查询某个范围内的地理位置。 2. 项目环境配置 2.1. 依赖引入 首先在 pom.xml 中引入 Spring Boot 3 和 Redis 的相关依赖具体参考重学SpringBoot3-集成Redis一之基本使用 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId /dependency2.2. Redis 配置 在 application.yml 中配置 Redis 连接 spring:data:redis:host: localhostport: 6379 # Redis 端口password: redis123456 # 如果有密码可以在这里配置lettuce:pool:max-active: 100 # 最大并发连接数max-idle: 50 # 最大空闲连接数min-idle: 10 # 最小空闲连接数3. GEO 数据存储和查询实现 3.1. 服务层实现 我们将通过 StringRedisTemplate 来操作 Redis 的 GEO 命令。 package com.coderjia.boot310redis.service;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResult; import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Point; import org.springframework.data.redis.connection.RedisGeoCommands; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service;import java.util.ArrayList; import java.util.List;/*** author CoderJia* create 2024/10/9 下午 10:10* Description**/ Service public class GeoLocationService {Autowiredprivate StringRedisTemplate redisTemplate;private static final String GEO_KEY city_locations;// 添加地理位置public void addGeoLocation(String cityName, double longitude, double latitude) {redisTemplate.opsForGeo().add(GEO_KEY, new Point(longitude, latitude), cityName);}// 获取地理位置public Point getGeoLocation(String cityName) {ListPoint positions redisTemplate.opsForGeo().position(GEO_KEY, cityName);return positions ! null !positions.isEmpty() ? positions.get(0) : null;}// 计算两个城市之间的距离public Distance getDistance(String city1, String city2) {return redisTemplate.opsForGeo().distance(GEO_KEY, city1, city2, RedisGeoCommands.DistanceUnit.KILOMETERS);}// 查找指定范围内的城市public ListString getCitiesWithinRadius(String cityName, double radius) {GeoResultsRedisGeoCommands.GeoLocationString results redisTemplate.opsForGeo().radius(GEO_KEY, cityName, new Distance(radius, RedisGeoCommands.DistanceUnit.KILOMETERS));ListString cities new ArrayList();if (results ! null) {for (GeoResultRedisGeoCommands.GeoLocationString result : results) {cities.add(result.getContent().getName());}}return cities;} }3.2. 控制层 为了方便测试我们可以通过简单的控制器来调用这些服务。 package com.coderjia.boot310redis.demos.web;import com.coderjia.boot310redis.service.GeoLocationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.geo.Distance; import org.springframework.data.geo.Point; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;import java.util.List;/*** author CoderJia* create 2024/10/9 下午 10:14* Description**/ RestController RequestMapping(/geo) public class GeoLocationController {Autowiredprivate GeoLocationService geoLocationService;// 添加城市位置PostMapping(/add)public String addCity(RequestParam(city) String city, RequestParam(lon) double lon, RequestParam(lat) double lat) {geoLocationService.addGeoLocation(city, lon, lat);return Added city;}// 查询城市位置GetMapping(/location)public Point getCityLocation(RequestParam(city) String city) {return geoLocationService.getGeoLocation(city);}// 计算两个城市之间的距离GetMapping(/distance)public Distance getDistance(RequestParam(city1) String city1, RequestParam(city2) String city2) {return geoLocationService.getDistance(city1, city2);}// 查找指定城市附近的城市GetMapping(/nearby)public ListString getNearbyCities(RequestParam(city) String city, RequestParam(radius) double radius) {return geoLocationService.getCitiesWithinRadius(city, radius);} }4. 使用示例 4.1. 添加城市位置信息 通过 POST 请求添加城市位置信息城市经纬度查询参考https://lbs.amap.com/tools/picker 添加北上广深杭五座城市 POST localhost:8080/geo/add?cityBeijinglon116.40lat39.90 POST localhost:8080/geo/add?cityShanghailon121.47lat31.23 POST localhost:8080/geo/add?cityGuangZhoulon113.26lat23.14 POST localhost:8080/geo/add?cityShenZhenlon114.06lat22.54 POST localhost:8080/geo/add?cityHangZhoulon120.12lat30.224.2. 查询城市位置信息 查询城市的经纬度信息 GET localhost:8080/geo/location?cityBeijing4.3. 计算两城市之间的距离 计算两个城市之间的距离 GET localhost:8080/geo/distance?city1Beijingcity2Shanghai4.4. 查询指定城市附近的其他城市 查询上海附近的其他城市比如 200 公里内的城市 GET localhost:8080/geo/nearby?cityShanghairadius2005. 总结 通过 Redis 的 GEO 命令集与 Spring Boot 3 集成我们可以轻松实现地理位置的存储与查询功能。这种方式不仅方便而且具有很高的性能尤其适用于地理位置相关的应用场景如地图服务、物流系统、附近商家查询等。 使用 Redis 进行地理位置存储的优势在于其操作简单、高效并且能够借助 Redis 内置的命令进行实时的距离计算和范围查询。如果你的应用涉及地理信息Redis 提供的 GEO 功能会是一个非常不错的选择。
http://www.hkea.cn/news/14318282/

相关文章:

  • wordpress 邮件 key如何优化网站打开速度
  • 墙绘做网站哪家好一个自己的网站
  • 山东滨州网站建设公司wordpress清空演示数据
  • 查询单位信息的网站重庆网站布局信息公司
  • c asp.net 发布网站品牌设计logo
  • 人员调动在网站上怎么做网站开发语言在那看出来
  • 网站标题在哪里如何自己做外贸网站
  • 公司网站建设手续超市微信小程序怎么做
  • 广东圆心科技网站开发网站模板设计创业网站模板
  • 域名对行业网站的作用wordpress转移服务器后不能访问
  • 大丰网站设计公司wordpress群站
  • 如何制作数据库网站网站怎么做看起来好看
  • 好的网站设计机构中国建设银行企业网站首页
  • 大理公司网站建设济南媒体邀约
  • 莆系医疗网站建设政务公开和网站建设先进个人
  • 烟台网站搜索优化图片 套网站模板下载 迅雷下载 迅雷下载地址
  • 卖视频会员个人网站怎么做葫芦岛做网站
  • 做网站推广怎么定位客户seo研究中心学员案例
  • 做社交网站需要什么资质wordpress访问数据库
  • 做网站业务员提成几个点做好门户网站建设
  • 网站策划是什么怎么建设淘客自己的网站、
  • 青羊区城乡建设网站05网全部答案数学
  • 网站备案查询官网入口网站关键词设置
  • 网站产品详情页怎么做中小企业加盟网站建设
  • deals网站建设计算机网络设计是干什么的
  • wordpress老站开启多站点请人做网站合同
  • 陕西省建设执业资格注册管理中心网站苏州网站建设设计公司
  • 做一个网站开发项目有哪些阶段深圳网络优化有限公司
  • 有一个网站叫浪什么腾讯云域名查询
  • 溧阳住房和城乡建设局网站wordpress做电商