private void setZoomLevel() {
    Object[] keys = map.keySet().toArray();
    OverlayItem item;
    if (keys.length > 1) {
      int minLatitude = Integer.MAX_VALUE;
      int maxLatitude = Integer.MIN_VALUE;
      int minLongitude = Integer.MAX_VALUE;
      int maxLongitude = Integer.MIN_VALUE;

      for (Object key : keys) {
        item = map.get((String) key);
        GeoPoint p = item.getPoint();
        int lati = p.getLatitudeE6();
        int lon = p.getLongitudeE6();

        maxLatitude = Math.max(lati, maxLatitude);
        minLatitude = Math.min(lati, minLatitude);
        maxLongitude = Math.max(lon, maxLongitude);
        minLongitude = Math.min(lon, minLongitude);
      }
      mapController.zoomToSpan(
          Math.abs(maxLatitude - minLatitude), Math.abs(maxLongitude - minLongitude));
      mapController.animateTo(
          new GeoPoint((maxLatitude + minLatitude) / 2, (maxLongitude + minLongitude) / 2));

    } else {
      String key = (String) keys[0];
      item = map.get(key);
      mapController.animateTo(item.getPoint());
      while (mapController.zoomIn()) {}

      mapController.zoomOut();
    }
  }
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   MapController mc = mapView.getController();
   switch (keyCode) {
     case KeyEvent.KEYCODE_I:
       mc.zoomIn();
       break;
     case KeyEvent.KEYCODE_O:
       mc.zoomOut();
       break;
   }
   return super.onKeyDown(keyCode, event);
 }
        @Override
        public void onDataReceived(DeviceAsyncData data) {
          if (data instanceof DeviceSensorsAsyncData) {
            ArrayList<DeviceSensorsData> datalist = ((DeviceSensorsAsyncData) data).getAsyncData();
            if (datalist != null) {
              for (DeviceSensorsData item : datalist) {
                AccelerometerData acc = item.getAccelerometerData();
                if (acc != null) {
                  xValue.setText(String.format("%.3f", acc.getFilteredAcceleration().x));
                  yValue.setText(String.format("%.3f", acc.getFilteredAcceleration().y));
                  zValue.setText(String.format("%.3f", acc.getFilteredAcceleration().z));

                  if (acc.getFilteredAcceleration().x > THRESHOLD_RIGHT) {
                    movementDescription.setText("You're moving right.");
                    controller.scrollBy(X_DISTANCE, 0);
                  }
                  if (acc.getFilteredAcceleration().x < THRESHOLD_LEFT) {
                    movementDescription.setText("You're moving left.");
                    controller.scrollBy(-X_DISTANCE, 0);
                  }
                  if (acc.getFilteredAcceleration().y > THRESHOLD_FORWARD) {
                    movementDescription.setText("You're moving forward.");
                    controller.scrollBy(0, -Y_DISTANCE);
                  }
                  if (acc.getFilteredAcceleration().y < THRESHOLD_BACKWARD) {
                    movementDescription.setText("You're moving backwards.");
                    controller.scrollBy(0, Y_DISTANCE);
                  }
                  if (acc.getFilteredAcceleration().z > THRESHOLD_ZOOM_OUT) {
                    movementDescription.setText("You're moving up.");
                    controller.zoomOut();
                  }
                  if (acc.getFilteredAcceleration().z < THRESHOLD_ZOOM_IN) {
                    movementDescription.setText("You're moving down.");
                    controller.zoomIn();
                  }
                }
                AttitudeData att = item.getAttitudeData();
                if (att != null) {
                  pitchValue.setText(
                      String.format("%s", att.getAttitudeSensor().pitch)); // yaw, roll
                  yawValue.setText(String.format("%s", att.getAttitudeSensor().yaw));
                  rollValue.setText(String.format("%s", att.getAttitudeSensor().roll));
                }
              }
            }
          }
        }
Exemple #4
0
  public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    TextView tv = (TextView) v;
    String address = tv.getText().toString();

    String[] aux = address.split(" ");
    address = new String();
    for (int i = 0; i < aux.length - 1; ++i) {
      if (i == 0) address = aux[i];
      else address = address + " " + aux[i];
    }

    SQLiteDatabase myDB = null;

    myDB = openOrCreateDatabase(DB_NAME, 1, null);

    myDB.execSQL(
        "CREATE TABLE IF NOT EXISTS "
            + TABLE
            + " ("
            + ADDR_DB
            + " TEXT NOT NULL PRIMARY KEY, "
            + COORD_X_DB
            + " INTEGER NOT NULL, "
            + COORD_Y_DB
            + " INTEGER NOT NULL, "
            + INF_DB
            + " TEXT, "
            + DAY_DB
            + " INTEGER, "
            + MONTH_DB
            + " INTEGER, "
            + YEAR_DB
            + " INTEGER);");

    String[] FROM = {COORD_X_DB, COORD_Y_DB};
    String WHERE = ADDR_DB + " = '" + address + "'";

    Cursor c = myDB.query(TABLE, FROM, WHERE, null, null, null, null);

    startManagingCursor(c);

    GeoPoint point = null;
    if (c.moveToNext()) {
      point = new GeoPoint(c.getInt(0), c.getInt(1));
    }

    c.close();
    if (myDB != null) myDB.close();

    tabHost.setCurrentTabByTag("Mapa");

    if (point != null) {
      controller.animateTo(point);
    }
    while (map.getZoomLevel() != 14) {
      if (map.getZoomLevel() < 14) {
        controller.zoomIn();
      } else if (map.getZoomLevel() > 14) {
        controller.zoomOut();
      }
    }
  }