Android 百度地图 增加路线点的密集度

来源:互联网 发布:淘宝转链接微信朋友圈 编辑:程序博客网 时间:2024/05/16 12:58
/** * 增加点的密度 */private void makeDenseRoutePoi() {    if (null != route && null != route.getAllStep()            && route.getAllStep().size() > 0) {        routePoiList.clear();        int stepCount = route.getAllStep().size();        List<DrivingStep> stepList = route.getAllStep();        for (int i = 0; i < stepCount; i++) {            List<LatLng> points = stepList.get(i).getWayPoints();            int pointCount = points.size();            for (int j = 0; j < pointCount; j++) {                LatLng p1 = null, p2 = null;                double dis = 0;                if (j + 1 < pointCount) {                    p1 = points.get(j);                    p2 = points.get(j + 1);                    dis = DistanceUtil.getDistance(p1, p2);                    // if(dis>200){                    //if (dis > 80) {                      if(dis>20){                        // 中间增加点,增大点密度                        double latDif = p2.latitude - p1.latitude;                        double lngDif = p2.longitude - p1.longitude;                        // 将过大的距离等分,20m切割一次,得到份数                        double count =  dis / 20;                          double latInterval = latDif / count;                        double lngInterval = lngDif / count;                        String latIntervalNew = String.format("%.6f",                                latInterval);                        String lngIntervalNew = String.format("%.6f",                                lngInterval);                        latInterval = Double.parseDouble(latIntervalNew);                        lngInterval = Double.parseDouble(lngIntervalNew);                        RoutePlanePointModel routePlan = new RoutePlanePointModel();                        routePlan.setBdLatitude(p1.latitude);                        routePlan.setBdLongitude(p1.longitude);                        routePoiList.add(routePlan);                         // int tempCount=(int)count;                          int tempCount=0;                          Log.i(TAG,"two poi cut count="+count);                          //份数,如果是小数,去掉小数点后面部分,如果是整数,减1,                          if((count+"").contains(".")){                              tempCount=(int)count;                          }else{                              //份数为整数,减1                              tempCount=(int)count-1;                          }                        for (int a = 0; a < tempCount; a++) {                            double latNew = p1.latitude + latInterval                                    * (a + 1);                            double lngNew = p1.longitude + lngInterval                                    * (a + 1);                            RoutePlanePointModel routePlanAdd = new RoutePlanePointModel();                            routePlanAdd.setBdLatitude(latNew);                            routePlanAdd.setBdLongitude(lngNew);                            routePoiList.add(routePlanAdd);                        }                    } else {                        RoutePlanePointModel routePlanAdd = new RoutePlanePointModel();                        LatLng latLng = points.get(j);                        routePlanAdd.setBdLatitude(latLng.latitude);                        routePlanAdd.setBdLongitude(latLng.longitude);                        routePoiList.add(routePlanAdd);                    }                } else {                    RoutePlanePointModel routePlanAdd = new RoutePlanePointModel();                    LatLng latLng = points.get(j);                    routePlanAdd.setBdLatitude(latLng.latitude);                    routePlanAdd.setBdLongitude(latLng.longitude);                    routePoiList.add(routePlanAdd);                }            }        }        dumpRouteInfo();    }

}

private void dumpRouteInfo() {    if(null!=routePoiList){        for (int i = 0; i < routePoiList.size()-1; i++) {            RoutePlanePointModel p1= routePoiList.get(i);            RoutePlanePointModel p2 = routePoiList.get(i + 1);         double p1Lat=   p1.getBdLatitude();        double p1Lng=p1.getBdLongitude();            LatLng p1LatLng=new LatLng(p1Lat,p1Lng);            double p2Lat=p2.getBdLatitude();            double p2Lng=p2.getBdLongitude();            LatLng p2Latlng=new LatLng(p2Lat,p2Lng);            double dis= DistanceUtil.getDistance(p1LatLng,p2Latlng);            LogFileUtils.getInstance().witeLogFile("after cut,route poi dis="+dis,3);        }    }}

0 0
原创粉丝点击