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

Java地图专题课 基本API BMapGLLib 地图找房案例 MongoDB

本课程基于百度地图技术,由基础入门开始到应用实战,适合零基础入门学习。将企业项目中地图相关常见应用场景的落地实战,包括有地图找房、轻骑小程序、金运物流等。同时讲了基于Netty实现高性能的web服务,来处理高并发的问题。还讲解了海量坐标数据处理解决方案。

学完本课程能够收获:百度地图技术的应用、轨迹类场景、路线规划场景,电子围栏场景的开发,增长开发经验。

导学

地图场景与基础API

案例1:地图找房

案例2:轻骑项目

案例3:金运物流

高并发解决方案

海量数据存储解决方案

地图基础API与搜索

地图技术概述

地图应用场景

常用地图服务的比较

百度地图基本API应用

百度地图提供了各种平台的SDK,地址:百度地图开放平台 | 百度地图API SDK | 地图开发 如下:

账号与API准备

设置应用名称与类型

JavaScript百度地图API项目

案例1:创建地图

创建地图的基本步骤如下:

编写HTML页面的基础代码

引入百度地图API文件

初始化地图逻辑以及设置各种参数

参考官方文档:

jspopularGL | 百度地图API SDK

页面效果:

<!DOCTYPE html>
<html>
<head><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Baidu Map </title><style type="text/css">html{height:100%}body{height:100%;margin:0px;padding:0px}#container{height:100%}</style><script type="text/javascript" src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=1GH6ZiAb79MTpfRzmYDpTUPpB7SVImfN"></script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">var map = new BMapGL.Map("container");          // 创建地图实例var point = new BMapGL.Point(116.404, 39.915);  // 创建点坐标map.centerAndZoom(point, 15);                 // 初始化地图,设置中心点坐标和地图级别map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放map.setHeading(64.5);   //设置地图旋转角度map.setTilt(73);       //设置地图的倾斜角度var scaleCtrl = new BMapGL.ScaleControl();  // 添加比例尺控件map.addControl(scaleCtrl);var zoomCtrl = new BMapGL.ZoomControl();  // 添加缩放控件map.addControl(zoomCtrl);var cityCtrl = new BMapGL.CityListControl();  // 添加城市列表控件map.addControl(cityCtrl);
</script>
</body>
</html>

添加覆盖物

<!DOCTYPE html>
<html>
<head><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Baidu Map - 覆盖物</title><style type="text/css">html{height:100%}body{height:100%;margin:0px;padding:0px}#container{height:100%}</style><script type="text/javascript" src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=LHHGlmhcb4ENvIXpR9QQ2tBYa6ooUowX"></script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">var map = new BMapGL.Map("container");          // 创建地图实例var point = new BMapGL.Point(116.404, 39.915);  // 创建点坐标map.centerAndZoom(point, 15);                 // 初始化地图,设置中心点坐标和地图级别map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放// var  point2 = new BMapGL.Point(116.380194,39.922018);// var marker = new BMapGL.Marker(point2);        // 创建标注// map.addOverlay(marker);                     // 将标注添加到地图中// var myIcon = new BMapGL.Icon("logo.png", new BMapGL.Size(180, 53), {//     // 指定定位位置。//     // 当标注显示在地图上时,其所指向的地理位置距离图标左上//     // 角各偏移10像素和25像素。您可以看到在本例中该位置即是//     // 图标中央下端的尖角位置。//     anchor: new BMapGL.Size(-10, 12),//     // 设置图片偏移。//     // 当您需要从一幅较大的图片中截取某部分作为标注图标时,您//     // 需要指定大图的偏移位置,此做法与css sprites技术类似。//     imageOffset: new BMapGL.Size(0, 0)   // 设置图片偏移// });// // 创建标注对象并添加到地图// var marker = new BMapGL.Marker(point, {icon: myIcon});// map.addOverlay(marker);//// marker.addEventListener("click", function(){//     alert("您点击了标注");// });// 折线var polyline = new BMapGL.Polyline([new BMapGL.Point(116.399, 39.910),new BMapGL.Point(116.405, 39.920),new BMapGL.Point(116.425, 39.900)], {strokeColor:"blue", strokeWeight:2, strokeOpacity:0.8});map.addOverlay(polyline);//多边形var polygon = new BMapGL.Polygon([new BMapGL.Point(116.387112,39.920977),new BMapGL.Point(116.385243,39.913063),new BMapGL.Point(116.394226,39.917988),new BMapGL.Point(116.401772,39.921364),new BMapGL.Point(116.41248,39.927893)], {strokeColor:"blue", strokeWeight:2, strokeOpacity:0.5});map.addOverlay(polygon);//圆形var circle = new BMapGL.Circle(point , 1000, {strokeColor:"red",strokeOpacity:0.8,strokeWeight:3});map.addOverlay(circle);</script>
</body>
</html>

地图事件

<!DOCTYPE html>
<html>
<head><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Baidu Map - 事件</title><style type="text/css">html{height:100%}body{height:100%;margin:0px;padding:0px}#container{height:100%}</style><script type="text/javascript" src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=LHHGlmhcb4ENvIXpR9QQ2tBYa6ooUowX"></script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">var map = new BMapGL.Map("container");          // 创建地图实例var point = new BMapGL.Point(116.404, 39.915);  // 创建点坐标map.centerAndZoom(point, 15);                 // 初始化地图,设置中心点坐标和地图级别map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放// map.addEventListener('click', function(e) {//     alert('click!')// });map.addEventListener('click', function(e) {alert('点击的经纬度:' + e.latlng.lng + ', ' + e.latlng.lat);var mercator = map.lnglatToMercator(e.latlng.lng, e.latlng.lat);alert('点的墨卡托坐标:' + mercator[0] + ', ' + mercator[1]);});</script>
</body>
</html>

地图样式

<!DOCTYPE html>
<html>
<head><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Baidu Map - 变更地图样式</title><style type="text/css">html{height:100%}body{height:100%;margin:0px;padding:0px}#container{height:100%}</style><script type="text/javascript" src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=LHHGlmhcb4ENvIXpR9QQ2tBYa6ooUowX"></script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">var map = new BMapGL.Map("container");          // 创建地图实例var point = new BMapGL.Point(116.404, 39.915);  // 创建点坐标map.centerAndZoom(point, 15);                 // 初始化地图,设置中心点坐标和地图级别map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放map.setMapType(BMAP_EARTH_MAP);      // 设置地图类型为地球模式</script>
</body>
</html>

地图检索

<!DOCTYPE html>
<html>
<head><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Baidu Map - 搜索兴趣点</title><style type="text/css">html{height:100%}body{height:100%;margin:0px;padding:0px}#container{height:100%}</style><script type="text/javascript" src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=LHHGlmhcb4ENvIXpR9QQ2tBYa6ooUowX"></script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">var map = new BMapGL.Map("container");          // 创建地图实例var point = new BMapGL.Point(116.404, 39.915);  // 创建点坐标map.centerAndZoom(point, 15);                 // 初始化地图,设置中心点坐标和地图级别map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放var local = new BMapGL.LocalSearch(map, {renderOptions:{map: map},pageCapacity:100});local.search("银行");
</script>
</body>
</html>

<!DOCTYPE html>
<html>
<head><meta name="viewport" content="initial-scale=1.0, user-scalable=no" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Baidu Map - 圆形范围搜索兴趣点</title><style type="text/css">html{height:100%}body{height:100%;margin:0px;padding:0px}#container{height:100%}</style><script type="text/javascript" src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=LHHGlmhcb4ENvIXpR9QQ2tBYa6ooUowX"></script>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">var map = new BMapGL.Map("container");          // 创建地图实例var point = new BMapGL.Point(116.404, 39.915);  // 创建点坐标map.centerAndZoom(point, 15);                 // 初始化地图,设置中心点坐标和地图级别map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放var circle = new BMapGL.Circle(point,2000,{fillColor:"blue", strokeWeight: 1 ,fillOpacity: 0.3, strokeOpacity: 0.3});map.addOverlay(circle);var local =  new BMapGL.LocalSearch(map, {renderOptions: {map: map, autoViewport: false}});local.searchNearby('景点',point,2000);</script>
</body>
</html>

数据可视化

MapV开发文档

百度地图web API应用

地址: web服务API | 百度地图API SDK

案例一:坐标转换

package cn.itcast.baidumap;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import org.junit.Test;public class TestBaiduWebApi {private String ak = "64Ut0Peo2Dsb1l43FRl1nReM0tBdpE3L";/*** 测试坐标转换服务*/@Testpublic void testGeoconv() {String url = "https://api.map.baidu.com/geoconv/v1/?coords=114.21892734521,29.575429778924&from=1&to=5&ak={}";url = StrUtil.format(url, ak);//发起get请求String body = HttpRequest.get(url).execute().body();System.out.println(body);}/*** 测试IP定位服务*/@Testpublic void testLocation(){String url = "https://api.map.baidu.com/location/ip?ak={}&ip=140.206.149.83&coor=bd09ll";url = StrUtil.format(url, ak);//发起get请求String body = HttpRequest.get(url).execute().body();System.out.println(body);}/*** 测试地点输入提示服务*/@Testpublic void testSuggestion(){String url = "https://api.map.baidu.com/place/v2/suggestion?query=清华大&region=北京&city_limit=true&output=json&ak={}";url = StrUtil.format(url, ak);//发起get请求String body = HttpRequest.get(url).execute().body();System.out.println(body);}/*** 测试路线规划*/@Testpublic void testDriving(){String url = "https://api.map.baidu.com/direction/v2/driving?alternatives=1&origin=40.009645,116.333374&destination=39.937016,116.453576&ak={}";url = StrUtil.format(url, ak);//发起get请求String body = HttpRequest.get(url).execute().body();System.out.println(body);}
}

案例二:IP定位服务

案例三:地点输入提示服务

案例四:路线规划

综合案例:地图找房

BMapGLLib

GitHub - huiyan-fe/BMapGLLib: 百度地图JSAPI GL版JavaScript开源工具库

<!DOCTYPE html>
<html>
<head><meta name="viewport" content="initial-scale=1.0, user-scalable=no"/><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>地图找房 - 地图搜索 </title><style type="text/css">html {height: 100%}body {height: 100%;margin: 0px;padding: 0px}#container {height: 100%}.district {width: 84px;height: 84px;line-height: 16px;font-size: 12px;display: flex;flex-direction: column;justify-content: center;border: 1px solid transparent;border-radius: 50%;overflow: hidden;text-align: center;font-family: PingFangSC-Semibold;color: #fff;background: #00ae66 !important;box-sizing: border-box;}.district i {font-size: 12px;color: hsla(0, 0%, 100%, .7);line-height: 12px;margin-top: 4px;font-style: normal;}#platform > div > div > div {background: none !important;}</style><script type="text/javascript" src="jquery-3.6.0.min.js"></script><script type="text/javascript"src="http://api.map.baidu.com/api?v=1.0&type=webgl&ak=LHHGlmhcb4ENvIXpR9QQ2tBYa6ooUowX"></script><script src="http://mapopen.bj.bcebos.com/github/BMapGLLib/RichMarker/src/RichMarker.min.js"></script>
</head>
<body>
<div id="container"></div>
<script type="application/javascript">function showInfo(map) {let bound = map.getBounds(); //可视范围矩形坐标,其中sw表示矩形区域的西南角,参数ne表示矩形区域的东北角let zoom = map.getZoom(); //缩放级别console.log(bound);console.log(zoom);$.ajax({url: "/house/search",data: {maxLongitude: bound.ne.lng,minLongitude: bound.sw.lng,maxLatitude: bound.ne.lat,minLatitude: bound.sw.lat,zoom: zoom},success: function (data) {showMapMarker(data, map);}});//测试效果:// let data = [{"name":"徐汇","price":"1028.43","total":"6584","longitude":121.43676,"latitude":31.18831},{"name":"黄浦","price":"1016.19","total":"7374","longitude":121.49295,"latitude":31.22337},{"name":"长宁","price":"1008.34","total":"4380","longitude":121.42462,"latitude":31.22036},{"name":"静安","price":"1005.34","total":"8077","longitude":121.4444,"latitude":31.22884},{"name":"普陀","price":"1026.14","total":"5176","longitude":121.39703,"latitude":31.24951},{"name":"金山","price":"1099.67","total":"6","longitude":121.34164,"latitude":30.74163},{"name":"松江","price":"1017.71","total":"14","longitude":121.22879,"latitude":31.03222},{"name":"青浦","price":"1038.11","total":"751","longitude":121.12417,"latitude":31.14974},{"name":"奉贤","price":"1108.63","total":"35","longitude":121.47412,"latitude":30.9179},{"name":"浦东","price":"1030.22","total":"8294","longitude":121.5447,"latitude":31.22249},{"name":"嘉定","price":"1041.45","total":"1620","longitude":121.2655,"latitude":31.37473},{"name":"宝山","price":"1050.65","total":"102","longitude":121.4891,"latitude":31.4045},{"name":"闵行","price":"1027.15","total":"941","longitude":121.38162,"latitude":31.11246},{"name":"杨浦","price":"1007.78","total":"2747","longitude":121.526,"latitude":31.2595},{"name":"虹口","price":"1025.81","total":"4187","longitude":121.48162,"latitude":31.27788}];// showMapMarker(data, map);}//显示覆盖物function showMapMarker(data, map) {for (let vo of data) {let html = "<div class=\"district\">" + vo.name + "<span>" + vo.price + "万</span><i>" + vo.total + "套</i></div>";let marker = new BMapGLLib.RichMarker(html, new BMapGL.Point(vo.longitude, vo.latitude));map.addOverlay(marker);}}//清除覆盖物function clearMapMarker(map) {let markers = map.getOverlays(); //获取到地图上所有的覆盖物for (let marker of markers) { //循环将其删除map.removeOverlay(marker);}}$(function () {//地图默认位置,上海市let defaultX = 121.48130241985999;let defaultY = 31.235156971414239;let defaultZoom = 12; //默认缩放比例let map = new BMapGL.Map("container");          // 创建地图实例let point = new BMapGL.Point(defaultX, defaultY);  // 创建点坐标map.centerAndZoom(point, defaultZoom);                 // 初始化地图,设置中心点坐标和地图级别map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放//显示比例尺map.addControl(new BMapGL.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT}));map.addEventListener("dragstart", () => {  //拖动开始事件clearMapMarker(map)});map.addEventListener("dragend", () => { //拖动结束事件showInfo(map)});map.addEventListener("zoomstart", () => { //缩放开始事件clearMapMarker(map)});map.addEventListener("zoomend", () => { //缩放结束事件showInfo(map)});//初始显示数据showInfo(map);});
</script>
</body>
</html>

通过docker安装MongoDB

#拉取镜像
docker pull mongo:4.0.3#创建容器
docker create --name mongodb-server -p 27017:27017 -v mongodb-data:/data/db mongo:4.0.3 --auth#启动容器
docker start mongodb-server#进入容器
docker exec -it mongodb-server /bin/bash#进入admin数据库
mongo
use admin#添加管理员,其拥有管理用户和角色的权限
db.createUser({ user: 'root', pwd: 'root', roles: [ { role: "root", db: "admin" } ] })
#退出后进行认证#进行认证
mongo -u "root" -p "root" --authenticationDatabase "admin"#通过admin添加普通用户
use admin
db.createUser({ user: 'house', pwd: 'oudqBFGmGY8pU6WS', roles: [ { role: "readWrite", db: "house" } ] });#通过tanhua用户登录进行测试
mongo -u "house" -p "oudqBFGmGY8pU6WS" --authenticationDatabase "admin"#发现可以正常进入控制台进行操作

构造数据

爬虫代码
package cn.itcast.baidumap.wm;import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.itcast.baidumap.pojo.BusinessCircle;
import cn.itcast.baidumap.pojo.Community;
import cn.itcast.baidumap.pojo.District;
import cn.itcast.baidumap.util.BaiduApiUtil;
import org.bson.types.ObjectId;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;public class CommunityPageProcessor implements PageProcessor {private District district;private BusinessCircle businessCircle;private MongoTemplate mongoTemplate;public CommunityPageProcessor(District district, BusinessCircle businessCircle, MongoTemplate mongoTemplate) {this.district = district;this.businessCircle = businessCircle;this.mongoTemplate = mongoTemplate;}@Overridepublic void process(Page page) {Document html = Jsoup.parse(page.getRawText()); //解析htmlElements elements = html.select("div.info div.title a"); //获取数据链接对象for (Element element : elements) {Community community = new Community();community.setId(ObjectId.get());community.setName(element.text()); //获取小区名称community.setLianJiaUrl(element.attr("href")); //获取链接community.setBusinessCircleCode(this.businessCircle.getCode());community.setDistrictCode(this.district.getCode());String address = StrUtil.format("上海市{}{}{}",this.district.getName(),this.businessCircle.getName(),community.getName());//通过百度地图api查询地址对应的经纬度double[] coordinate = BaiduApiUtil.queryCoordinateByAddress(address);community.setLocation(new GeoJsonPoint(coordinate[0], coordinate[1]));this.mongoTemplate.save(community);}//设置分页String pageData = html.select("div[page-data]").attr("page-data");JSONObject pageJson = JSONUtil.parseObj(pageData);Integer totalPage = pageJson.getInt("totalPage", 1);Integer curPage = pageJson.getInt("curPage", 1);if (curPage < totalPage) {String url = businessCircle.getLianJiaUrl() + "pg" + (curPage + 1);page.addTargetRequest(url);}}@Overridepublic Site getSite() {//失败重试3次,每次抓取休息200毫秒return Site.me().setRetryTimes(3).setSleepTime(200);}
}

MongoDB的聚合操作

实现搜索—分析

POJO类、Vo类

Controller

package cn.itcast.baidumap.controller;import cn.itcast.baidumap.service.HouseSearchService;
import cn.itcast.baidumap.vo.HouseResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
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;@RequestMapping("house/search")
@RestController
public class HouseSearchController {@Autowiredprivate HouseSearchService houseSearchService;/*** 地图找房搜索服务** @param maxLongitude 最大经度* @param minLongitude 最小经度* @param maxLatitude  最大纬度* @param minLatitude  最小纬度* @param zoom         地图缩放比例值* @return*/@GetMappingpublic List<HouseResultVo> search(@RequestParam("maxLongitude") Double maxLongitude,@RequestParam("minLongitude") Double minLongitude,@RequestParam("maxLatitude") Double maxLatitude,@RequestParam("minLatitude") Double minLatitude,@RequestParam("zoom") Double zoom) {return this.houseSearchService.search(maxLongitude, minLongitude, maxLatitude, minLatitude, zoom);}
}

Service

package cn.itcast.baidumap.service;import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import cn.itcast.baidumap.pojo.BusinessCircle;
import cn.itcast.baidumap.pojo.Community;
import cn.itcast.baidumap.pojo.District;
import cn.itcast.baidumap.pojo.House;
import cn.itcast.baidumap.vo.HouseResultVo;
import com.mongodb.internal.operation.AggregateOperation;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Box;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.*;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;import java.util.ArrayList;
import java.util.Collections;
import java.util.List;@Service
public class HouseSearchService {@Autowiredprivate MongoTemplate mongoTemplate;/*** 地图找房搜索服务** @param maxLongitude 最大经度* @param minLongitude 最小经度* @param maxLatitude  最大纬度* @param minLatitude  最小纬度* @param zoom         地图缩放比例值* @return*/public List<HouseResultVo> search(Double maxLongitude,Double minLongitude,Double maxLatitude,Double minLatitude,Double zoom) {//收集聚合查询条件List<AggregationOperation> operationList = new ArrayList<>();//在可视范围内搜索Box box = new Box(new double[]{maxLongitude, maxLatitude}, new double[]{minLongitude, minLatitude});MatchOperation matchOperation = Aggregation.match(Criteria.where("location").within(box));operationList.add(matchOperation);int type;GroupOperation groupOperation;//根据地图的缩放比例进行分组if (zoom < 13.5) { //2公里以上//按照行政区分组groupOperation = Aggregation.group("districtCode");type = 1;} else if (zoom < 15.5) { //200米以上//按照商圈分组groupOperation = Aggregation.group("businessCircleCode");type = 2;} else { //200以下//按照小区分组groupOperation = Aggregation.group("communityId");type = 3;}groupOperation = groupOperation.count().as("total").avg("price").as("price");operationList.add(groupOperation);//生成最终的聚合条件Aggregation aggregation = Aggregation.newAggregation(operationList);//执行查询AggregationResults<HouseResultVo> aggregationResults = this.mongoTemplate.aggregate(aggregation, House.class, HouseResultVo.class);List<HouseResultVo> houseResultVoList = aggregationResults.getMappedResults();if (CollUtil.isEmpty(houseResultVoList)) {return Collections.emptyList();}//填充数据switch (type) {case 1: {//查询行政区数据for (HouseResultVo houseResultVo : houseResultVoList) {District district = this.queryDistrictByCode(Convert.toInt(houseResultVo.getCode()));houseResultVo.setName(district.getName());houseResultVo.setLongitude(district.getLocation().getX());houseResultVo.setLatitude(district.getLocation().getY());//价格保留2位小数houseResultVo.setPrice(NumberUtil.roundStr(houseResultVo.getPrice(), 2));}break;}case 2: {//查询商圈数据for (HouseResultVo houseResultVo : houseResultVoList) {BusinessCircle businessCircle = this.queryBusinessCircleByCode(Convert.toInt(houseResultVo.getCode()));houseResultVo.setName(businessCircle.getName());houseResultVo.setLongitude(businessCircle.getLocation().getX());houseResultVo.setLatitude(businessCircle.getLocation().getY());//价格保留2位小数houseResultVo.setPrice(NumberUtil.roundStr(houseResultVo.getPrice(), 2));}break;}case 3: {//查询小区数据for (HouseResultVo houseResultVo : houseResultVoList) {Community community = this.queryCommunityById(new ObjectId(houseResultVo.getCode()));houseResultVo.setName(community.getName());houseResultVo.setLongitude(community.getLocation().getX());houseResultVo.setLatitude(community.getLocation().getY());//价格保留2位小数houseResultVo.setPrice(NumberUtil.roundStr(houseResultVo.getPrice(), 2));}break;}default: {return Collections.emptyList();}}return houseResultVoList;}/*** 根据code查询行政区数据** @param code* @return*/private District queryDistrictByCode(Integer code) {Query query = Query.query(Criteria.where("code").is(code));return this.mongoTemplate.findOne(query, District.class);}/*** 根据code查询商圈数据** @param code* @return*/private BusinessCircle queryBusinessCircleByCode(Integer code) {Query query = Query.query(Criteria.where("code").is(code));return this.mongoTemplate.findOne(query, BusinessCircle.class);}/*** 根据code查询小区数据** @return*/private Community queryCommunityById(ObjectId id) {return this.mongoTemplate.findById(id, Community.class);}
}

非常感谢您阅读到这里,如果这篇文章对您有帮助,希望能留下您的点赞👍 关注💖 收藏 💕评论💬感谢支持!!!

相关文章:

Java地图专题课 基本API BMapGLLib 地图找房案例 MongoDB

本课程基于百度地图技术&#xff0c;由基础入门开始到应用实战&#xff0c;适合零基础入门学习。将企业项目中地图相关常见应用场景的落地实战&#xff0c;包括有地图找房、轻骑小程序、金运物流等。同时讲了基于Netty实现高性能的web服务&#xff0c;来处理高并发的问题。还讲…...

vue实现可缩放拖拽盒子(亲测可用)

特征 没有依赖 使用可拖动&#xff0c;可调整大小或两者兼备定义用于调整大小的句柄限制大小和移动到父元素或自定义选择器将元素捕捉到自定义网格将拖动限制为垂直或水平轴保持纵横比启用触控功能使用自己的样式为句柄提供自己的样式 安装和基本用法 npm install --save vue-d…...

python一次性导出项目用到的依赖

导出依赖列表 如果你用到了Anaconda&#xff0c;记得先激活环境!!!! 下载pipreqs pip install pipreqs 在项目的根目录新建一个run_pipreqs.py文件&#xff0c;复制一下代码&#xff1a; # -*- coding: utf-8 -*- import os import subprocessos.environ["PYTHONIOE…...

移动端网页中的前端视频技术探索

引言 随着移动设备的普及和网络速度的提升&#xff0c;移动端网页中的视频播放已经成为了越来越重要的功能需求。本篇博客将介绍一些在移动端网页中实现前端视频播放的技术探索&#xff0c;并提供详细的代码示例。 1. 基本视频标签 在移动端网页中实现视频播放最基本的方法就…...

题解:ABC277C - Ladder Takahashi

题解&#xff1a;ABC277C - Ladder Takahashi 题目 链接&#xff1a;Atcoder。 链接&#xff1a;洛谷。 难度 算法难度&#xff1a;普及。 思维难度&#xff1a;入门。 调码难度&#xff1a;入门。 综合评价&#xff1a;简单。 算法 深度优先搜索简单图论 思路 把每…...

7.11 Java方法重写

7.11 Java方法重写 这里首先要确定的是重写跟属性没有关系&#xff0c;重写都是方法的重写&#xff0c;与属性无关 带有关键字Static修饰的方法的重写实例 父类实例 package com.baidu.www.oop.demo05;public class B {public static void test(){System.out.println("这…...

Android Stodio编译JNI项目,Cmake出错:Detecting C compiler ABI info - failed

在使用Android Stodio编译JNI项目时出现Cmake错误&#xff0c;报错如下&#xff1a; Execution failed for task :app:configureCMakeDebug[arm64-v8a]. > [CXX1429] error when building with cmake using C:\Users\Dell\AndroidStudioProjects\MyApplication2\app\src\ma…...

6.2 Spring Boot整合MyBatis

1、基于Spring BootMyBatis的学生信息系统的设计与实现案例 基于Spring BootMyBatis实现学生信息的新增、修改、删除、查询功能&#xff0c;并实现MySQL数据库的操作。 MySQL数据库创建学生表&#xff08;t_student&#xff09;&#xff0c;有主键、姓名、年龄、性别、出生日…...

在CentOS 7上使用kubeadm部署Kubernetes集群

如有错误&#xff0c;敬请谅解&#xff01; 此文章仅为本人学习笔记&#xff0c;仅供参考&#xff0c;如有冒犯&#xff0c;请联系作者删除&#xff01;&#xff01; 前言&#xff1a; Kubernetes是一个开源的容器编排平台&#xff0c;用于管理和自动化部署容器化的应用程序。…...

这6个免费设计素材网站,设计师都在用,马住

新手设计师不知道去哪里找素材&#xff0c;那就看看这几个设计师都在用的网站吧&#xff0c;免费、付费、商用素材都有&#xff0c;可根据需求选择&#xff0c;赶紧收藏~ 菜鸟图库 https://www.sucai999.com/?vNTYxMjky 菜鸟图库是一个非常大的素材库&#xff0c;站内包含设…...

uni-app引入sortable列表拖拽,兼容App和H5,拖拽排序。

效果: 拖拽排序 背景&#xff1a; 作为一名前端开发人员&#xff0c;在工作中难免会遇到拖拽功能&#xff0c;分享一个github上一个不错的拖拽js库&#xff0c;能满足我们在项目开发中的需要&#xff0c;下面是我在uniapp中使用SortableJS的使用详细流程&#xff1b; vue开发…...

Redis-内存淘汰算法

Redis可以存多少数据 32位的操作系统默认3G 谁现在用32位啊?我们说64位的 一般来讲是不设上限的 但是我们也可以主动配置maxmemory, maxmemory支持各单位: maxmemory 1024 (默认字节) maxmemory 1024KB maxmemory 1024MB maxmemory 1204GB 当Redis存储超过这个配置值&#…...

Git 合并分支时允许合并不相关的历史

git fetch git fetch 是 Git 的一个命令&#xff0c;用于从远程仓库中获取最新的提交和数据&#xff0c;同时更新本地仓库的远程分支指针。 使用 git fetch 命令可以获取远程仓库的最新提交&#xff0c;但并不会自动合并或修改本地分支。它会将远程仓库的提交和引用&#xff…...

世界上最著名的密码学夫妻的历史

Alice和Bob是密码学领域里最著名的虚拟夫妻&#xff0c;自1978年“诞生”以来&#xff0c;到走进二十一世纪的移动互联网时代&#xff0c;作为虚构的故事主角&#xff0c;Alice和Bob不仅在计算机理论、逻辑学、量子计算等与密码学相关的领域中得到应用&#xff0c;他们的名字也…...

二维码网络钓鱼攻击泛滥!美国著名能源企业成主要攻击目标

近日&#xff0c;Cofense发现了一次专门针对美国能源公司的网络钓鱼攻击活动&#xff0c;攻击者利用二维码将恶意电子邮件塞进收件箱并绕过安全系统。 Cofense 方面表示&#xff0c;这是首次发现网络钓鱼行为者如此大规模的使用二维码进行钓鱼攻击&#xff0c;这表明他们可能正…...

前端面试题-CSS

1. 盒模型 ⻚⾯渲染时&#xff0c; dom 元素所采⽤的 布局模型。可通过 box-sizing 进⾏设置。根据计算宽⾼的区域可分为 content-box ( W3C 标准盒模型)border-box ( IE 盒模型)padding-boxmargin-box (浏览器未实现) 2. BFC 块级格式化上下⽂&#xff0c;是⼀个独⽴的渲染…...

6.1 安全漏洞与网络攻击

数据参考&#xff1a;CISP官方 目录 安全漏洞及产生原因信息收集与分析网络攻击实施后门设置与痕迹清除 一、安全漏洞及产生原因 什么是安全漏洞 安全漏洞也称脆弱性&#xff0c;是计算机系统存在的缺陷 漏洞的形式 安全漏洞以不同形式存在漏洞数量逐年递增 漏洞产生的…...

STM32--EXTI外部中断

前文回顾---STM32--GPIO 相关回顾--有关中断系统简介 目录 STM32中断 NVIC EXTI外部中断 AFIO EXTI框图 旋转编码器简介 对射式红外传感器工程 代码&#xff1a; 旋转编码器工程 代码&#xff1a; STM32中断 先说一下基本原理&#xff1a; 1.中断请求发生&#xff1a…...

Python + Selenium 处理浏览器Cookie

工作中遇到这么一个场景&#xff1a;自动化测试登录的时候需要输入动态验证码&#xff0c;由于某些原因&#xff0c;需要从一个已登录的机器上&#xff0c;复制cookie过来&#xff0c;到自动化这边绕过登录。 浏览器的F12里复制出来的cookie内容是文本格式的&#xff1a; uui…...

文件的导入与导出

文章目录 一、需求二、分析1. Excel 表格数据导出2. Excel 表格数据导入一、需求 在我们日常开发中,会有文件的导入导出的需求,如何在 vue 项目中写导入导出功能呢 二、分析 以 Excel 表格数据导出为例 1. Excel 表格数据导出 调用接口将返回的数据进行 Blob 转换,附: 接…...

[2025CVPR]DeepVideo-R1:基于难度感知回归GRPO的视频强化微调框架详解

突破视频大语言模型推理瓶颈,在多个视频基准上实现SOTA性能 一、核心问题与创新亮点 1.1 GRPO在视频任务中的两大挑战 ​安全措施依赖问题​ GRPO使用min和clip函数限制策略更新幅度,导致: 梯度抑制:当新旧策略差异过大时梯度消失收敛困难:策略无法充分优化# 传统GRPO的梯…...

在 Nginx Stream 层“改写”MQTT ngx_stream_mqtt_filter_module

1、为什么要修改 CONNECT 报文&#xff1f; 多租户隔离&#xff1a;自动为接入设备追加租户前缀&#xff0c;后端按 ClientID 拆分队列。零代码鉴权&#xff1a;将入站用户名替换为 OAuth Access-Token&#xff0c;后端 Broker 统一校验。灰度发布&#xff1a;根据 IP/地理位写…...

【快手拥抱开源】通过快手团队开源的 KwaiCoder-AutoThink-preview 解锁大语言模型的潜力

引言&#xff1a; 在人工智能快速发展的浪潮中&#xff0c;快手Kwaipilot团队推出的 KwaiCoder-AutoThink-preview 具有里程碑意义——这是首个公开的AutoThink大语言模型&#xff08;LLM&#xff09;。该模型代表着该领域的重大突破&#xff0c;通过独特方式融合思考与非思考…...

Qwen3-Embedding-0.6B深度解析:多语言语义检索的轻量级利器

第一章 引言&#xff1a;语义表示的新时代挑战与Qwen3的破局之路 1.1 文本嵌入的核心价值与技术演进 在人工智能领域&#xff0c;文本嵌入技术如同连接自然语言与机器理解的“神经突触”——它将人类语言转化为计算机可计算的语义向量&#xff0c;支撑着搜索引擎、推荐系统、…...

论文解读:交大港大上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架(一)

宇树机器人多姿态起立控制强化学习框架论文解析 论文解读&#xff1a;交大&港大&上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架&#xff08;一&#xff09; 论文解读&#xff1a;交大&港大&上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化…...

在WSL2的Ubuntu镜像中安装Docker

Docker官网链接: https://docs.docker.com/engine/install/ubuntu/ 1、运行以下命令卸载所有冲突的软件包&#xff1a; for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done2、设置Docker…...

C++ Visual Studio 2017厂商给的源码没有.sln文件 易兆微芯片下载工具加开机动画下载。

1.先用Visual Studio 2017打开Yichip YC31xx loader.vcxproj&#xff0c;再用Visual Studio 2022打开。再保侟就有.sln文件了。 易兆微芯片下载工具加开机动画下载 ExtraDownloadFile1Info.\logo.bin|0|0|10D2000|0 MFC应用兼容CMD 在BOOL CYichipYC31xxloaderDlg::OnIni…...

蓝桥杯 冶炼金属

原题目链接 &#x1f527; 冶炼金属转换率推测题解 &#x1f4dc; 原题描述 小蓝有一个神奇的炉子用于将普通金属 O O O 冶炼成为一种特殊金属 X X X。这个炉子有一个属性叫转换率 V V V&#xff0c;是一个正整数&#xff0c;表示每 V V V 个普通金属 O O O 可以冶炼出 …...

中医有效性探讨

文章目录 西医是如何发展到以生物化学为药理基础的现代医学&#xff1f;传统医学奠基期&#xff08;远古 - 17 世纪&#xff09;近代医学转型期&#xff08;17 世纪 - 19 世纪末&#xff09;​现代医学成熟期&#xff08;20世纪至今&#xff09; 中医的源远流长和一脉相承远古至…...

短视频矩阵系统文案创作功能开发实践,定制化开发

在短视频行业迅猛发展的当下&#xff0c;企业和个人创作者为了扩大影响力、提升传播效果&#xff0c;纷纷采用短视频矩阵运营策略&#xff0c;同时管理多个平台、多个账号的内容发布。然而&#xff0c;频繁的文案创作需求让运营者疲于应对&#xff0c;如何高效产出高质量文案成…...