예제 #1
0
  private MapPosition getLocation(Location bestLocation) {
    byte zoom = mTileMap.getMapPosition().getMapPosition().zoomLevel;
    float scale = mTileMap.getMapPosition().getMapPosition().scale;
    if (zoom < 15) {
      zoom = (byte) 15;
      scale = 0;
    }

    MapPosition mapPosition =
        new MapPosition(bestLocation.getLatitude(), bestLocation.getLongitude(), zoom, scale, 0);
    return mapPosition;
  }
예제 #2
0
  @SuppressWarnings("deprecation")
  public boolean enableShowMyLocation(boolean centerAtFirstFix) {
    Log.d("TileMap", "enableShowMyLocation " + mShowMyLocation);

    gotoLastKnownPosition();

    if (!mShowMyLocation) {
      Criteria criteria = new Criteria();
      criteria.setAccuracy(Criteria.NO_REQUIREMENT);
      String bestProvider = mLocationManager.getBestProvider(criteria, true);

      if (bestProvider == null) {
        // mTileMap.showDialog(DIALOG_LOCATION_PROVIDER_DISABLED);
        return false;
      }
      mShowMyLocation = true;
      enableMyLocation();
      Log.d("TileMap", "enableShowMyLocation " + mShowMyLocation);

      mLocationListener.setFirstCenter(centerAtFirstFix);

      mSnapToLocationView.setVisibility(View.VISIBLE);
      mTileMap.invalidate();
      return true;
    }
    return false;
  }
예제 #3
0
  void gotoLastKnownPosition() {
    Location currentLocation;
    Location bestLocation = null;

    for (String provider : mLocationManager.getProviders(true)) {
      currentLocation = mLocationManager.getLastKnownLocation(provider);
      if (currentLocation == null) continue;
      if (bestLocation == null || currentLocation.getAccuracy() < bestLocation.getAccuracy()) {
        bestLocation = currentLocation;
      }
    }

    if (bestLocation != null) {
      MapPosition mapPosition = getLocation(bestLocation);

      mTileMap.setMapCenter(mapPosition);
      accuracy = bestLocation.getAccuracy();
      mLocation = bestLocation;
      mTileMap.mapActivity.invalidateMap();

    } else {
      // mTileMap.showToastOnUiThread(mTileMap
      // .getString(R.string.error_last_location_unknown));
    }
  }
예제 #4
0
  /**
   * Enables the "snap to location" mode.
   *
   * @param showToast defines whether a toast message is displayed or not.
   */
  public void enableSnapToLocation(boolean showToast) {
    if (!mSnapToLocation) {
      mSnapToLocation = true;
      mShowMyLocation = true;
      mTileMap.setClickable(false);

      if (showToast) {
        // mTileMap.showToastOnUiThread(mTileMap
        // .getString(R.string.snap_to_location_enabled));
      }
    }
  }
예제 #5
0
  /**
   * Disables the "snap to location" mode.
   *
   * @param showToast defines whether a toast message is displayed or not.
   */
  public void disableSnapToLocation(boolean showToast) {
    mLocation = null;
    if (mSnapToLocation) {
      mSnapToLocation = false;
      mSnapToLocationView.setChecked(false);

      mTileMap.setClickable(true);

      if (showToast) {
        // mTileMap.showToastOnUiThread(mTileMap
        // .getString(R.string.snap_to_location_disabled));
      }
    }
  }