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);}
}

非常感謝您閱讀到這里,如果這篇文章對您有幫助,希望能留下您的點贊👍 關注💖 收藏 💕評論💬感謝支持!!!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/36328.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/36328.shtml
英文地址,請注明出處:http://en.pswp.cn/news/36328.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ttf-dejavu fontconfig字體

ttf-dejavu fontconfig是驗證碼&#xff0c;pdf&#xff0c;excel時需要用到的字體 編輯dockerfile&#xff0c;先切換國內鏡像源&#xff0c;默認alpinelinux是國外源&#xff0c;下載包會很慢 vim Dockerfile FROM alpine:latest RUN sed -i s/dl-cdn.alpinelinux.org/mirr…

【創建型設計模式】C#設計模式之原型模式

原型模式是一種創建型設計模式&#xff0c;它通過復制現有對象來創建新對象&#xff0c;而無需通過實例化的方式。它允許我們使用已經存在的對象作為藍本&#xff0c;從而創建新的對象&#xff0c;這樣可以避免重復初始化相似的對象&#xff0c;提高了對象的創建效率。 現在給…

Sentinel

1、熔斷降級限流 熔斷 A服務調用B服務的某個功能&#xff0c;由于網絡不穩定、B服務卡機等問題&#xff0c;導致功能時間超長。如果這樣子的次數太多&#xff0c;我們就可以直接將B斷路&#xff08;A不再請求B接口&#xff09;&#xff0c;凡是調用B服務的直接返回降級數據&a…

13-數據結構-串以及KMP算法,next數組

串 目錄 串 一、串&#xff1a; 二、串的存儲結構&#xff1a; 三、模式匹配 1.簡單模式匹配&#xff08;BF算法&#xff09; 2.KMP算法 2.1-next&#xff08;j&#xff09;數組手工求解 2.2-nextval&#xff08;j&#xff09;數組手工求解 一、串&#xff1a; 內容受…

JVM垃圾回收篇-垃圾回收算法

JVM垃圾回收篇-垃圾回收算法 標記清除&#xff08;Mark Sweep&#xff09; 概念 collector指的就是垃圾收集器。 mutator是指除了垃圾收集器之外的部分&#xff0c;比如說我們的應用程序本身。 mutator的職責一般是NEW(分配內存)、READ(從內存中讀取內容)、WRITE(將內容寫入內…

將多個單獨的 Excel 文件合并成一個,并添加標題行

要將多個單獨的 Excel 文件合并成一個&#xff0c;并添加標題行&#xff0c;可以使用 Python 的 pandas 庫。以下是一個示例代碼&#xff0c;假設要合并的 Excel 文件都在同一個文件夾中&#xff1a; import os import pandas as pd # 指定文件夾路徑 folder_path path/to/fo…

vscode搭建c語言環境問題

c語言環境搭建參考文章:【C語言初級階段學習1】使用vscode運行C語言&#xff0c;vscode配置環境超詳細過程&#xff08;包括安裝vscode和MinGW-W64安裝及后續配置使用的詳細過程&#xff0c;vscode用戶代碼片段的使用&#xff09;[考研專用]_QAQshift的博客-CSDN博客 問題如下:…

[C++ 網絡協議] 套接字和地址族、數據序列

目錄 1. 套接字 1.1 在Linux平臺下構建套接字 1.1.1 用于接聽的套接字(服務器端套接字) 1.1.2 用于發送請求的套接字(客戶端套接字) 1.2 在Windows平臺下構建套接字 1.2.1 Winsock的初始化 1.2.2 用于接聽的套接字(服務器端套接字) 1.2.3 用于發送請求的套接字(客戶端套…

pytest框架快速進階篇-pytest前置和pytest后置,skipif跳過用例

一、Pytest的前置和后置方法 1.Pytest可以集成unittest實現前置和后置 importunittestimportpytestclassTestCase(unittest.TestCase):defsetUp(self)->None:print(unittest每個用例前置)deftearDown(self)->None:print(unittest每個用例后置)classmethoddefsetUpClass…

jmeter中用戶參數和用戶定義的變量的區別

如果使用jmeter做過參數化的人都知道&#xff0c;參數化的方式有多種&#xff0c;其中一種就是使用用戶定義的變量&#xff0c;還有一種是使用用戶參數。那么&#xff0c;這兩個有什么異同呢&#xff1f; 一、先說相同的點&#xff1a; 1、都可以參數化&#xff0c;以供sample…

allure測試報告

使用pytest結合Allure進行測試報告生成的簡單教程 allure測試報告 Allure基于Java開發&#xff0c;因此我們需要提前安裝Java 8或以上版本的環境。 ◆安裝allure-pytest插件在DOS窗口輸入命令“pip3 install allure-pytest”&#xff0c;然后按“Enter”鍵。 下載安裝Allure…

使用 Docker 部署 canal 服務實現MySQL和ES實時同步

文章目錄 0. 環境介紹0. 前置步驟1. 安裝Kibana和Elasticsearch2. 安裝Canal和Canal Adapter2.1 修改數據庫配置2.1.1 修改配置2.1.2 驗證mysql binlog配置2.1.3 查看日志文件2.1.4 用JDBC代碼插入數據庫 2.2 安裝Canal Server2.3 安裝Canal Adapter修改兩處配置文件配置文件取…

Linux 命令篇

一、啟動網絡命令 ip addr 查看網卡信息 service network start 啟動網卡 service network stop 關閉網卡 service network restart 重啟網絡 二、pwd 命令 查看當前目錄的路徑 linux 下所有的絕對路徑都是從根目錄 "/" 開始 root:是linux下root用戶的根目…

初識mysql數據庫之引入mysql客戶端庫

目錄 一、下載第三方庫 1. 準備工作 1. 使用mysql官網提供的庫 2. yum源安裝 二、測試第三方庫是否可用 三、mysql常用接口介紹 1. 查看官方文檔 2. 初始化 3. 關閉mysql 4. 連接mysql 5. 下達sql指令 四、一個簡單的C客戶端庫連接mysql程序 1. 頭文件 2. 初始化…

FFmpeg接收UDP碼流

一、FFmpeg參數初始化&#xff1a; //在打開碼流前指定各種參數比如:探測時間/超時時間/最大延時等//設置緩存大小,1080p可將值調大av_dict_set(&options, "buffer_size", "8192000", 0);//以tcp方式打開,如果以udp方式打開將tcp替換為udpav_dict_set(…

Could not resolve host: mirrorlist.centos.org; Unknown error解決方法

今天服務器安裝完CentOS系統后&#xff0c;安裝網絡的時候&#xff0c;出現無法聯網yum yum -y install net-tools 以上代碼無法運行并報錯&#xff0c;這里我要提醒大家&#xff0c;如果在初始安裝的時候選中安裝網絡工具模塊就不用在安裝net-tools了&#xff0c;因為我選中…

Angular 性能優化實戰

Angular 性能優化實戰 Angular 是一個非常強大的前端框架&#xff0c;但是如果不注意性能優化&#xff0c;應用程序可能會變得非常慢并增加加載時間。 以下是一些Angular性能優化經驗的實戰建議&#xff1a; 1. 使用 OnPush 變更檢測策略 默認情況下&#xff0c;Angular檢查…

vite跨域配置踩坑,postman鏈接后端接口正常,但是前端就是不能正常訪問

問題一&#xff1a;怎么都鏈接不了后端地址 根據以下配置&#xff0c;發現怎么都鏈接不了后端地址&#xff0c;proxy對了呀。 仔細看&#xff0c;才發現host有問題 // 本地運行配置&#xff0c;及反向代理配置server: {host: 0,0,0,0,port: 80,// cors: true, // 默認啟用并允…

爆肝整理,性能測試方法與關鍵指標以及瓶頸定位思路,一篇貫通...

目錄&#xff1a;導讀 前言一、Python編程入門到精通二、接口自動化項目實戰三、Web自動化項目實戰四、App自動化項目實戰五、一線大廠簡歷六、測試開發DevOps體系七、常用自動化測試工具八、JMeter性能測試九、總結&#xff08;尾部小驚喜&#xff09; 前言 性能測試方法 1、…

Python編程實現百度AI開放平臺的接口對接方法,詳解和實踐指南

Python編程實現百度AI開放平臺的接口對接方法,詳解和實踐指南 引言 百度AI開放平臺提供了豐富的人工智能接口,包括語音識別、圖像識別、自然語言處理等功能。本文將通過Python編程,詳解如何對接百度AI開放平臺的接口,并提供實際代碼示例。準備工作 在開始之前,我們需要先完…