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

四川北路街道网站建设温州软件开发公司有哪些

四川北路街道网站建设,温州软件开发公司有哪些,企业商务网站设计与开发,制作企业网站的公司文章目录 前言redis geospatial如何从地图上获取经纬度springboot 的相关方法调用准备redis服务器引用的依赖预设位置的keyGEOADD 添加位置GEORADIUS 获取指定经纬度附件的停车场#xff08;deprecated#xff09;GEORADIUS 获取指定成员附件的停车场#xff08;deprecateddeprecatedGEORADIUS 获取指定成员附件的停车场deprecatedGEOSEARCH 搜索指定经纬度附件的停车场GEOSEARCH 搜索指定成员附件的停车场GEOPOS获取指定成员经纬度GEODIST获取两点之间的距离GEOHASH获取坐标的hashZREM 移除位置 数学球面计算两点距离 前言 基于redis geospatial的应用比较广泛比如需要获取附件5公里的停车场。 官方文档https://redis.io/docs/data-types/geospatial/ 代码已分享至Gitee:https://gitee.com/lengcz/redisgeo redis geospatial 用于地理位置服务的计算它能做哪些 我周边的共享单车的信息可以按距离输出两坐标、车辆之间的距离 如何从地图上获取经纬度 高德地图 https://lbs.amap.com/demo/javascript-api/example/map/click-to-get-lnglat/ 百度地图 https://api.map.baidu.com/lbsapi/getpoint/index.html springboot 的相关方法调用 准备redis服务器 需要安装redis 服务器 引用的依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdscopetest/scope/dependency注意本demo中的springboot版本为2.7.15如果你的版本较低可能部分GEOSEARCH 的API不可用。 如果遇到demo中的示例出现报红请考虑是否为依赖版本过低。 预设位置的key private String positionKey parking;GEOADD 添加位置 官方文档: https://redis.io/commands/geoadd/ GEOADD key [NX | XX] [CH] longitude latitude member [longitudelatitude member ...]注意经纬度需要在范围内 经度 -180到180纬度 -85.05112878到85.05112878 如果你添加的经纬度超出范围会报错 XX 仅更新已存在的元素。永远不要添加元素。 NX不要更新已经存在的元素。始终添加新元素。 CH将返回值从添加的新元素数量修改为更改的元素总数CH是changed的缩写。已更改的图元是添加的新元素和已更新坐标的现有图元。因此命令行中指定的分数与过去相同的元素将不被计算在内。注意通常情况下GEOADD的返回值只计算添加的新元素数量。 Testvoid geoAdd(Autowired RedisTemplate redisTemplate) {System.out.println(--------添加位置-----);GeoOperations geoOperations redisTemplate.opsForGeo();{Long addedNum geoOperations.add(positionKey, new Point(-122.27652, 37.805186), 10001:市图书馆);System.out.println(addedNum);}{Long addedNum geoOperations.add(positionKey, new Point(-122.2674626, 37.8062344), 10002:百货大楼);System.out.println(addedNum);}{Long addedNum geoOperations.add(positionKey, new Point(-122.2469854, 37.8104049), 10003:科学中心);System.out.println(addedNum);}{Long addedNum geoOperations.add(positionKey, new Point(-122.2625112, 37.793513), 10004:博物馆);System.out.println(addedNum);}System.out.println(--------添加位置END-----);}GEORADIUS 获取指定经纬度附件的停车场deprecated 官方文档: https://redis.io/commands/georadius/ 从Redis版本6.2.0开始此命令被视为已弃用。 在迁移或编写新代码时可以用带有BYRADIUS参数的GEOSEARCH和GEOSEARCHSTORE替换它。 GEORADIUS key longitude latitude radius M | KM | FT | MI[WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count [ANY]] [ASC | DESC][STORE key | STOREDIST key]单位 m 米km 千米mi 英里ft 英尺 Testvoid geoRadius(Autowired RedisTemplate redisTemplate) {// 指定经纬度附近5公里的停车场Circle circle new Circle(new Point(-122.2612767, 37.793684), RedisGeoCommands.DistanceUnit.KILOMETERS.getMultiplier());RedisGeoCommands.GeoRadiusCommandArgs args RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs().includeCoordinates().includeDistance().sortAscending().limit(5);GeoResultsRedisGeoCommands.GeoLocationString results redisTemplate.opsForGeo().radius(positionKey, circle, args);System.out.println(results);for (GeoResultRedisGeoCommands.GeoLocationString g : results) {System.out.println(g);String addr g.getContent().getName();System.out.println(addr: addr ,distance: g.getDistance().getValue());}}运行结果 GeoResult [content: RedisGeoCommands.GeoLocation(name10004:博物馆, pointPoint [x-122.262509, y37.793512]), distance: 109.9417 METERS, ] addr:10004:博物馆,distance:109.9417 GeoResult [content: RedisGeoCommands.GeoLocation(name10002:百货大楼, pointPoint [x-122.267460, y37.806234]), distance: 1497.9608 METERS, ] addr:10002:百货大楼,distance:1497.9608 GeoResult [content: RedisGeoCommands.GeoLocation(name10001:市图书馆, pointPoint [x-122.276520, y37.805185]), distance: 1852.3499 METERS, ] addr:10001:市图书馆,distance:1852.3499 GeoResult [content: RedisGeoCommands.GeoLocation(name10003:科学中心, pointPoint [x-122.246984, y37.810404]), distance: 2244.1523 METERS, ] addr:10003:科学中心,distance:2244.1523GEORADIUS 获取指定成员附件的停车场deprecated Testvoid geoRadius2(Autowired RedisTemplate redisTemplate) {// 指定地址附近5公里的停车场RedisGeoCommands.GeoRadiusCommandArgs args RedisGeoCommands.GeoRadiusCommandArgs.newGeoRadiusArgs().includeCoordinates().includeDistance().sortAscending().limit(5);GeoResultsRedisGeoCommands.GeoLocationString results redisTemplate.opsForGeo().radius(positionKey, 10001:市图书馆, new Distance(5, Metrics.KILOMETERS), args);System.out.println(results);for (GeoResultRedisGeoCommands.GeoLocationString g : results) {System.out.println(g);String addr g.getContent().getName();System.out.println(addr: addr ,distance: g.getDistance().getValue());}}执行结果 GeoResult [content: RedisGeoCommands.GeoLocation(name10001:市图书馆, pointPoint [x-122.276520, y37.805185]), distance: 0.0 KILOMETERS, ] addr:10001:市图书馆,distance:0.0 GeoResult [content: RedisGeoCommands.GeoLocation(name10002:百货大楼, pointPoint [x-122.267460, y37.806234]), distance: 0.8047 KILOMETERS, ] addr:10002:百货大楼,distance:0.8047 GeoResult [content: RedisGeoCommands.GeoLocation(name10004:博物馆, pointPoint [x-122.262509, y37.793512]), distance: 1.7894 KILOMETERS, ] addr:10004:博物馆,distance:1.7894 GeoResult [content: RedisGeoCommands.GeoLocation(name10003:科学中心, pointPoint [x-122.246984, y37.810404]), distance: 2.6597 KILOMETERS, ] addr:10003:科学中心,distance:2.6597 GEOSEARCH 搜索指定经纬度附件的停车场 官方文档: https://redis.io/commands/geosearch/ 注意该命令从redis 6.0.2开始。 GEOSEARCH key FROMMEMBER member | FROMLONLAT longitude latitudeBYRADIUS radius M | KM | FT | MI | BYBOX width height M | KM |FT | MI [ASC | DESC] [COUNT count [ANY]] [WITHCOORD] [WITHDIST][WITHHASH]Testvoid geoSearch(Autowired RedisTemplate redisTemplate) {// 指定经纬度附近5公里的停车场RedisGeoCommands.GeoSearchCommandArgs geoSearchCommandArgs RedisGeoCommands.GeoSearchCommandArgs.newGeoSearchArgs().includeCoordinates().includeDistance().sortAscending();GeoResultsRedisGeoCommands.GeoLocation searchResult redisTemplate.opsForGeo().search(positionKey, new GeoReference.GeoCoordinateReference(-122.2612767, 37.793684), new Distance(5, Metrics.KILOMETERS), geoSearchCommandArgs); // System.out.println(searchResult);ListGeoResultRedisGeoCommands.GeoLocation content searchResult.getContent();for (GeoResultRedisGeoCommands.GeoLocation g : content) { // System.out.println(g);RedisGeoCommands.GeoLocation content1 g.getContent();Distance distance g.getDistance();System.out.println(content1: content1 ,distance: distance);}}执行结果 content1:RedisGeoCommands.GeoLocation(name10004:博物馆, pointPoint [x-122.262509, y37.793512]),distance:0.1099 KILOMETERS content1:RedisGeoCommands.GeoLocation(name10001:市图书馆, pointPoint [x-122.276520, y37.805185]),distance:1.8523 KILOMETERS content1:RedisGeoCommands.GeoLocation(name10003:科学中心, pointPoint [x-122.246984, y37.810404]),distance:2.2442 KILOMETERSGEOSEARCH 搜索指定成员附件的停车场 Testvoid geoSearch2(Autowired RedisTemplate redisTemplate) {// 指定成员附近5公里的停车场RedisGeoCommands.GeoSearchCommandArgs geoSearchCommandArgs RedisGeoCommands.GeoSearchCommandArgs.newGeoSearchArgs().includeCoordinates().includeDistance().sortAscending();GeoResultsRedisGeoCommands.GeoLocation searchResult redisTemplate.opsForGeo().search(positionKey, new GeoReference.GeoMemberReference(10004:博物馆), new Distance(5, Metrics.KILOMETERS), geoSearchCommandArgs); // System.out.println(searchResult);ListGeoResultRedisGeoCommands.GeoLocation content searchResult.getContent();for (GeoResultRedisGeoCommands.GeoLocation g : content) { // System.out.println(g);RedisGeoCommands.GeoLocation content1 g.getContent();Distance distance g.getDistance();System.out.println(content1: content1 ,distance: distance);}}执行结果 content1:RedisGeoCommands.GeoLocation(name10004:博物馆, pointPoint [x-122.262509, y37.793512]),distance:0.0 KILOMETERS content1:RedisGeoCommands.GeoLocation(name10001:市图书馆, pointPoint [x-122.276520, y37.805185]),distance:1.7894 KILOMETERS content1:RedisGeoCommands.GeoLocation(name10003:科学中心, pointPoint [x-122.246984, y37.810404]),distance:2.3219 KILOMETERSGEOPOS获取指定成员经纬度 官方文档 https://redis.io/commands/geopos/ GEOPOS key [member [member ...]]Testvoid geoGetPoints(Autowired RedisTemplate redisTemplate) {ListPoint points redisTemplate.opsForGeo().position(positionKey, 10003:科学中心, 10004:博物馆);System.out.println(points);}执行结果 [Point [x-122.246984, y37.810404], Point [x-122.262509, y37.793512]]GEODIST获取两点之间的距离 官方文档: https://redis.io/commands/geodist/ 命令 GEODIST key member1 member2 [M | KM | FT | MI]单位 m 米km 千米mi 英里ft 英尺 Testpublic void testDist(Autowired RedisTemplate redisTemplate) {Distance distance redisTemplate.opsForGeo().distance(positionKey, 10003:科学中心, 10004:博物馆, RedisGeoCommands.DistanceUnit.KILOMETERS);System.out.println(distance);}执行结果 2.3219 KILOMETERSGEOHASH获取坐标的hash 官方文档: https://redis.io/commands/geohash/ GEOHASH key [member [member ...]]这里给定的10005不存在 Testpublic void testGeoHash(Autowired RedisTemplate redisTemplate) {ListString results redisTemplate.opsForGeo().hash(positionKey, 10004:博物馆, 10002:百货大楼, 10005:欢乐海岸);System.out.println(results);}执行结果 [9q9p1b55jj0, 9q9p1drt380, null]ZREM 移除位置 官方没有GEODEL需要使用ZREM命令 官方文档: https://redis.io/commands/zrem/ Testpublic void testGeoRemove(Autowired RedisTemplate redisTemplate) {Long remove redisTemplate.opsForGeo().remove(positionKey, 10002:百货大楼);ListString results redisTemplate.opsForGeo().hash(positionKey, 10004:博物馆, 10002:百货大楼, 10005:欢乐海岸);System.out.println(results);}执行结果,可以看到10002百货大楼已经被移除了。 [9q9p1b55jj0, null, null]注意: redis geo没有GEODEL命令需要使用ZREM命令删除元素 数学球面计算两点距离 /*** 通过球面计算距离*/ public class DistanceUtil {/*** 赤道半径(m)*/public final static double RC 6378137;/*** 极半径(m)*/public final static double RJ 6356725;/*** 将角度转化为弧度*/public static double radians(double d) {return d * Math.PI / 180.0;}/*** 根据两点经纬度((longitude and latitude))坐标计算直线距离* p* S 2arcsin√sin²(a/2)cos(lat1)*cos(lat2)*sin²(b/2)*6378137* p* 1. lng1 lat1 表示A点经纬度lng2 lat2 表示B点经纬度br* 2. alat1 – lat2 为两点纬度之差 blng1 -lng2 为两点经度之差br* 3. 6378137为地球赤道半径单位为米** param longitude1 点1经度* param latitude1 点1纬度* param longitude2 点2经度* param latitude2 点2纬度* return 距离单位米(M)* see a href* https://zh.wikipedia.org/wiki/%E5%8D%8A%E6%AD%A3%E7%9F%A2%E5%85%AC%E5%BC%8F* 半正矢(Haversine)公式/a*/public static double getDistanceFromToLngLat(double longitude1, double latitude1, double longitude2, double latitude2) {// 将角度转化为弧度double radLongitude1 radians(longitude1);double radLatitude1 radians(latitude1);double radLongitude2 radians(longitude2);double radLatitude2 radians(latitude2);double a radLatitude1 - radLatitude2;double b radLongitude1 - radLongitude2;return 2 * Math.asin(Math.sqrt(Math.sin(a / 2) * Math.sin(a / 2) Math.cos(radLatitude1) * Math.cos(radLatitude2) * Math.sin(b / 2) * Math.sin(b / 2))) * (RC);}/*** 获取指定角度方向上的经纬度(longitude and latitude)br* 以原始点的经纬度为基点,构建XY二维坐标线,则angle角度则从x轴起算。br* 说明:LBS查找,东西南北四个方向的最远点构建矩形,在矩形框方位内, 才有可能是该距离方位内的坐标,然后利用距离公式从小范围内找坐标** param origLongitude 基点经度* param origLatitude 基点纬度* param distance 距离(m)* param angle 角度(0~360)* param 经纬度(该角度指定距离的经纬度)*/public static Coordinate getCoordinate(double origLongitude, double origLatitude, double distance, double angle) {double x distance * Math.sin(angle * Math.PI / 180.0);double y distance * Math.cos(angle * Math.PI / 180.0);double r RJ (RC - RJ) * (90.0 - origLongitude) / 90.0;//由于地球不是标准的球体中间粗两头细这里計算平均半徑rdouble d r * Math.cos(origLongitude * Math.PI / 180);double newLongitude (y / r origLongitude * Math.PI / 180.0) * 180.0 / Math.PI;double newLatitude (x / d origLatitude * Math.PI / 180.0) * 180.0 / Math.PI;return new Coordinate(newLongitude, newLatitude);} }测试用例用例的经纬度为GEOSEARCH示例中目标到科学中心的距离 Testvoid getDist() {double longitude1 -122.2612767;double latitude1 37.793684;double longitude2 -122.2469854;double latitude2 37.8104049;double distance DistanceUtil.getDistanceFromToLngLat(longitude1, latitude1, longitude2, latitude2);System.out.println(经纬度( longitude1 , latitude1 )到( longitude2 , latitude2 )的距离为: distance 米);}运行测试用例返回结果与GEO返回的结果基本吻合。 经纬度(-122.2612767,37.793684)到(-122.2469854,37.8104049)的距离为: 2246.057783614703 米
http://www.yutouwan.com/news/336627/

相关文章:

  • 巩义企业网站托管服务商网络图片素材
  • 崇信县门户网站首页销售平台网站建设
  • 赣州哪里可以做网站北京做机柜空调的网站
  • 昌乐网站制作价格3 建设营销型网站流程图
  • 长沙长沙h5网站建设sem扫描电子显微镜
  • 富阳网站建站公司哪家好wordpress cms系统
  • 做网站学哪方面知识wordpress页面调用子页面内容
  • 网站后台生成文章很慢网站开发后台软件
  • 网站项目评价较好网站建设公司
  • 长沙 外贸网站建设公司上海对外贸易公司
  • 上海网站建设报价方案wordpress本地环境搭建
  • 做外贸的人常用的网站徐汇网站制作设计
  • 网站的建站程序网站开发实用技术
  • 网站建设手机源码抖音代运营海报
  • 南宁专业网站制作app接入广告变现
  • t云建站短视频免费素材网站
  • 网站建设专家论证会红动中国免费素材网
  • 其它区便宜营销型网站建设推荐深圳设计师品牌
  • 彩票网站开发制作需要什么钢丝网片
  • 商城类网站功能个人网站 外贸
  • 十堰网站制作公司电话wordpress的安装包
  • 南宁有做校园门户网站的吗3d全景网站怎么做
  • 浦口国家建设部网站江苏九天建设有限公司网站
  • 大数据统计网站网站开发小工具
  • 百度搜索 网站图片wordpress 釆集插件
  • php网站建设难点小微企业如何注册
  • 银川网站建设哪家优质朋友圈广告推广
  • 玉溪做网站公司设计一个网站先做哪些构造
  • 百度指数的网站网站美工做确认取消对话框
  • 做盗文网站广州天极营销型网站