日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

google s2 java开发文档

發布時間:2024/3/13 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 google s2 java开发文档 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近需要做運營商信號地圖,需要檢索某一區域用戶上報的信號質量問題,所以需要用到空間檢索能力,經過調研,geohash和google s2都可以實現相關的能力,但是geohash只有12級別,無法做細粒度的索引,google s2有30level,針對1公里甚至1cm都可以做索引,最終選擇google s2 的level12 13 14三個級別作為索引。

maven依賴

<!-- google s2 --> <dependency><groupId>io.sgr</groupId><artifactId>s2-geometry-library-java</artifactId><version>1.0.0</version> </dependency>
  • 根據坐標建立cell,level選擇13級別,覆蓋范圍1平方公里。將cell存入數據庫中,作為索引字段
  • import com.google.common.geometry.*; double lat=30.2; double lng=116.3; int currentLevel =13; S2LatLng s2LatLng = S2LatLng.fromDegrees(lat, lng); S2CellId cellId = S2CellId.fromLatLng(s2LatLng).parent(currentLevel);

    ? 2.獲取cell的四個頂點

    class Gps {private double wgLat;private double wgLon;public Gps(double wgLat, double wgLon) {setWgLat(wgLat);setWgLon(wgLon);}public double getWgLat() {return wgLat;}public void setWgLat(double wgLat) {this.wgLat = wgLat;}public double getWgLon() {return wgLon;}public void setWgLon(double wgLon) {this.wgLon = wgLon;}@Overridepublic String toString() {return wgLat + "," + wgLon;} }//由于google s2默認使用gps坐標系,在國內無法使用,需要轉換為國內的gcj坐標或者bd09坐標,轉換方法可自行上網查詢 List<Gps> points = new ArrayList();S2CellId curId = new S2CellId(35234364754L); S2Cell curCell = new S2Cell(curId); S2LatLng v0 = new S2LatLng(curCell.getVertex(0)); //將gps坐標轉換為bd09坐標 Gps gps0 = PositionUtils.gps84_To_Bd09(v0.latDegrees(), v0.lngDegrees()); points.add(gps0);S2LatLng v1 = new S2LatLng(curCell.getVertex(1)); Gps gps1 = PositionUtils.gps84_To_Bd09(v1.latDegrees(), v1.lngDegrees()); points.add(gps1);S2LatLng v2 = new S2LatLng(curCell.getVertex(2)); Gps gps2 = PositionUtils.gps84_To_Bd09(v2.latDegrees(), v2.lngDegrees()); points.add(gps2);S2LatLng v3 = new S2LatLng(curCell.getVertex(3)); Gps gps3 = PositionUtils.gps84_To_Bd09(v3.latDegrees(), v3.lngDegrees()); points.add(gps3);return points;

    3.獲取level為7的cell的所有level為9的cell

    S2CellId cellId = new S2CellId(3654375874L); childrenCell(cellId,9);public static List<S2CellId> childrenCell(S2CellId cellId, int desLevel) {List<S2CellId> list = childrenCellId(new ArrayList<S2CellId>(), cellId, cellId.level(), desLevel);return list;}private static List<S2CellId> childrenCellId(List<S2CellId> list, S2CellId cellId, int currentLevel, int desLevel) {if (currentLevel < desLevel) {long interval = cellId.childEnd().id() - cellId.childBegin().id();interval = interval / 4;for (int i = 0; i < 4; i++) {long id = cellId.childBegin().id() + interval * i;S2CellId newCellId = new S2CellId(id);//System.out.println(newCellId);childrenCellId(list, newCellId, currentLevel + 1, desLevel);}} else {list.add(cellId);return list;}return list;}

    4.獲取矩形區域內所有的cell

    S2LatLng startS2 = S2LatLng.fromDegrees(lat, lng); S2LatLng endS2 = S2LatLng.fromDegrees(lat1, lng1); S2LatLngRect rect = new S2LatLngRect(startS2, endS2);//獲取region區域內的cell S2RegionCoverer s2RegionCoverer = new S2RegionCoverer(); s2RegionCoverer.setMaxLevel(14); s2RegionCoverer.setMinLevel(13); S2CellUnion covering = s2RegionCoverer.getCovering(rect); return covering.cellIds();

    ?

    總結

    以上是生活随笔為你收集整理的google s2 java开发文档的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。