private void countDiatance(List<LatLng> pts, double speed[]) {
   double abc = 0.0;
   for (int i = 0; i < pts.size() - 1; i++) {
     abc = abc + DistanceUtil.getDistance(pts.get(i), pts.get(i + 1));
     if (speed[i] > 2.0) {
       driving_road = driving_road + (int) DistanceUtil.getDistance(pts.get(i), pts.get(i + 1));
       driving_dur = driving_dur + 1;
     } else {
       walking_road = walking_road + (int) DistanceUtil.getDistance(pts.get(i), pts.get(i + 1));
       walking_dur = walking_dur + 1;
     }
   }
   distanceLong = distanceLong + abc;
 }
Пример #2
0
 /**
  * 根据地图当前中心位置的纬度,当前比例尺,得出比例尺图标应该显示多长(多少像素)
  *
  * @param map
  * @param scale
  * @return
  */
 public static int meterToPixels(MapView map, int scale) {
   int mScaleMaxWidth;
   int mScaleMaxHeight;
   mScaleMaxWidth = widthWin >> 2;
   mScaleMaxHeight = heightWin >> 1;
   Point stpoint = new Point(0, mScaleMaxHeight);
   Point edpoint = new Point(mScaleMaxWidth, mScaleMaxHeight);
   double distance =
       DistanceUtil.getDistance(
           map.getMap().getProjection().fromScreenLocation(stpoint),
           map.getMap().getProjection().fromScreenLocation(edpoint));
   int dis = 0;
   int width = 20;
   if (map.getMap().getMapStatus().zoom == 19) {
     dis = SCALES[0];
     width = 52;
   } else if (map.getMap().getMapStatus().zoom == 3) {
     dis = SCALES[16];
     width = 80;
   } else {
     for (int i = 1; i < SCALES.length; i++) {
       if (SCALES[i - 1] <= distance && distance < SCALES[i]) {
         dis = SCALES[i - 1];
         break;
       }
     }
     width = (int) (dis * mScaleMaxWidth / distance);
   }
   return width;
 }
Пример #3
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   // TODO Auto-generated method stub
   ViewHolder vh = null;
   if (convertView == null) {
     convertView =
         ((MainActivity) ctx)
             .getLayoutInflater()
             .inflate(R.layout.item_maintenance_none, parent, false);
     vh = new ViewHolder(convertView);
     convertView.setTag(vh);
   } else {
     vh = (ViewHolder) convertView.getTag();
   }
   Map<String, Object> workorder = data.get(position);
   vh.tvFaultType.setText(workorder.get("faultType").toString());
   vh.tvMaintenanceNoneAddress.setText(workorder.get("address").toString());
   if (latitude == 0 || longitude == 0) {
     vh.tvMaintenanceNoneDistance.setText("??");
   } else {
     double distance =
         DistanceUtil.getDistance(
             curLatLng,
             new LatLng(
                 Double.parseDouble(workorder.get("latitude").toString()),
                 Double.parseDouble(workorder.get("longitude").toString())));
     vh.tvMaintenanceNoneDistance.setText(Utilities.format2decimal(distance / 1000.0) + "km");
   }
   vh.tvMaintenancePublishTime.setText(workorder.get("publishDatetime").toString());
   return convertView;
 }
Пример #4
0
  public void onGetPoiResult(PoiResult result) {

    if (result == null || result.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) {

      Toast.makeText(
              MainActivity.this,
              getResources().getString(R.string.notFoundResult),
              Toast.LENGTH_LONG)
          .show();
      return;
    }

    int first = 0;

    if (result.error == SearchResult.ERRORNO.NO_ERROR) {
      for (PoiInfo poi : result.getAllPoi()) {
        if (poi.type == PoiInfo.POITYPE.BUS_STATION) {
          // Log.i("Nearby poiresult",""+poi.name+"-"+poi.address);

          if (first == 0) {

            // 创建PoiOverlay
            overlay = new MyPoiOverlay(mBaiduMap);
            // 设置overlay可以处理标注点击事件
            mBaiduMap.setOnMarkerClickListener(overlay);
            // 设置PoiOverlay数据
            overlay.setData(result);
            // 添加PoiOverlay到地图中
            overlay.addToMap();
            overlay.zoomToSpan();

            first = 1;
          }

          HashMap<String, Object> map = new HashMap<String, Object>();
          map.put("name", poi.name);
          map.put("address", poi.address);
          // 计算距离当前位置的距离
          double distance =
              DistanceUtil.getDistance(OneBusApplication.CURRENT_LOCATION, poi.location);
          map.put("distance", (int) distance + "米");
          mStationList.add(map);

          // return;
        }
      }
    }
  }
Пример #5
0
  private void showInfoView(MyPoiInfo info) {
    rl_info.setVisibility(View.VISIBLE);

    tv_name.setText(info.name);
    tv_addr.setText(info.address);

    double distance =
        DistanceUtil.getDistance(
            new LatLng(cLoc.getLatitude(), cLoc.getLongitude()), new LatLng(info.lat, info.lng));

    if (distance > 1000) {
      tv_distance.setText(String.format("%.2f千米", distance / 100.0));
    } else {
      tv_distance.setText(String.format("%d米", (int) distance));
    }

    btn_do.setText(type == 1 ? "前往" : "详情");

    rl_info.setTag(type == 1 ? info : null);
  }
Пример #6
0
  private void handleGetDistance(String[] params) {
    if (params.length < 4) {
      return;
    }
    try {

      double lat1 = Double.valueOf(params[0]);
      double lon1 = Double.valueOf(params[1]);
      double lat2 = Double.valueOf(params[2]);
      double lon2 = Double.valueOf(params[3]);

      double distance = -1;

      LatLng p1 = new LatLng(lat1, lon1);
      LatLng p2 = new LatLng(lat2, lon2);
      distance = DistanceUtil.getDistance(p1, p2);

      // // 判断,如果是小距离
      // if ((Math.abs(lat1 - lat2) < MyDistanceUtils.SMALL_DISTANCE_FLAG)
      // && (Math.abs(lon1 - lon2) < MyDistanceUtils.SMALL_DISTANCE_FLAG))
      // {
      // distance = MyDistanceUtils.getShortDistance(lon1, lat1, lon2,
      // lat2);
      // }
      // // 大距离
      // else {
      // distance = MyDistanceUtils.getLongDistance(lon1, lat1, lon2,
      // lat2);
      // }

      jsCallback(EBaiduMapUtils.MAP_FUN_CB_GET_DISTANCE, 0, EUExCallback.F_C_TEXT, "" + distance);

    } catch (NumberFormatException e) {
      e.getStackTrace();
    }
  }
Пример #7
0
 public static void setDistanceWithUserAndVehicle(LatLng a, LatLng b) {
   double d = ((double) (DistanceUtil.getDistance(a, b) / 1000.000));
   distanceWithUserAndVehicle = String.format("%.2f", d);
 }