コード例 #1
0
 public void paintTasks() {
   allOverlays = mapView.getOverlays();
   allOverlays.remove(tasksPositionOverlay);
   tasksPositionOverlay = new TasksOverlay(doneMarker, this);
   tasksCursor = global_app.getDataStorage().getAllTasks();
   DecimalFormat km = new DecimalFormat();
   km.setMaximumFractionDigits(2);
   DecimalFormat m = new DecimalFormat();
   m.setMaximumFractionDigits(1);
   while (tasksCursor.moveToNext()) {
     double lat = tasksCursor.getDouble(tasksCursor.getColumnIndex(DataStorage.C_LAT));
     double lon = tasksCursor.getDouble(tasksCursor.getColumnIndex(DataStorage.C_LON));
     String taskTitle = (tasksCursor.getString(tasksCursor.getColumnIndex(DataStorage.C_NAME)));
     int taskState = (tasksCursor.getInt(tasksCursor.getColumnIndex(DataStorage.C_STATE)));
     int taskId = (tasksCursor.getInt(tasksCursor.getColumnIndex(DataStorage.C_ID)));
     GeoPoint taskLocation = new GeoPoint((int) (lat * 1E6), (int) (lon * 1E6));
     Location tmp = new Location(provider);
     tmp.setLatitude(lat);
     tmp.setLongitude(lon);
     double distance = lastLocation.distanceTo(tmp);
     String prettyDistance;
     if (distance > 1000) prettyDistance = km.format(distance / 1000) + "km";
     else prettyDistance = m.format(distance) + "m";
     OverlayItem taskOverlayItem =
         new OverlayItem(
             taskLocation,
             taskTitle + " (id: " + Integer.toString(taskId) + ")",
             "oddalone o: " + prettyDistance);
     Drawable marker;
     switch (taskState) {
       case 0:
         marker = cancelMarker;
         break;
       case 1:
         marker = pendingMarker;
         break;
       case 2:
         marker = currentMarker;
         break;
       default:
         marker = doneMarker;
         break;
     }
     int w = marker.getIntrinsicWidth();
     int h = marker.getIntrinsicHeight();
     marker.setBounds(-w / 2, -h, w / 2, 0);
     taskOverlayItem.setMarker(marker);
     tasksPositionOverlay.addOverlay(taskOverlayItem);
   }
   allOverlays.add(tasksPositionOverlay);
   mapView.invalidate();
   tasksCursor.close();
 }
コード例 #2
0
  public void paintCurrentPostion() {
    int lat = (int) ((new Double(lastLocation.getLatitude())) * 1E6);
    int lng = (int) ((new Double(lastLocation.getLongitude())) * 1E6);
    geoPoint = new GeoPoint(lat, lng);

    allOverlays = mapView.getOverlays();
    allOverlays.remove(updatablePositionOverlay);
    updatablePositionOverlay = new TasksOverlay(userMarker, this);
    updatablePositionOverlay.addOverlay(
        new OverlayItem(
            geoPoint,
            global_app.getUsername(),
            Double.toString(Double.valueOf(lastLocation.getLatitude()))
                + " "
                + Double.toString(Double.valueOf(lastLocation.getLongitude()))));
    allOverlays.add(updatablePositionOverlay);
    mapView.invalidate();
  }