コード例 #1
0
  /**
   * computes a geopoint the is the central geopoint between the user and the car. also it zooms so
   * both marks are visible on the map
   *
   * @author ricky barrette
   */
  protected void showBoth() {
    if (mMap != null) {
      if (mCarPoint == null) {
        Toast.makeText(getActivity(), R.string.mark_car_first, Toast.LENGTH_LONG).show();
      } else if (mMap.getUserLocation() == null) {
        Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
      } else {
        if (mMap.getMap() != null) {
          mMap.getMap().getController().stopAnimation(false);
          mMap.followUser(false);
          final GeoPoint user = mMap.getUserLocation();

          /*
           * here we null check our next set of value before we send
           * them off to geoutils if they have became null for some
           * reason we disable show both mode
           */
          if (mCarPoint != null && user != null) {
            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        mHandler.sendMessage(
                            mHandler.obtainMessage(MIDPOINT, GeoUtils.midPoint(mCarPoint, user)));
                      }
                    })
                .start();
          }

        } else {
          Log.e(TAG, "showBoth.mMap.getMap() is null");
        }
      }
    }
  }
コード例 #2
0
  /**
   * using the users lat/lon saves car location to lat/lon files and passes that geopoint info to
   * setCar also writes address to notes
   *
   * @author ricky barrette 3-31-2010
   * @author WWPowers 3-31-2010
   */
  private void markCar() {
    // removed old parking timer
    // ParkingTimerDialog.stopTimer(this);

    GeoPoint user = mMap.getUserLocation();

    /*
     * if the user location is not null then save car lat and lon to files
     * pass geopoint info to set car, which will setup and show the car
     * overlay get address info and add it to the notes file
     *
     * else inform user that they dont have a gps signal
     */
    if (user != null) {
      mSettings
          .edit()
          .putInt(Settings.LAT, user.getLatitudeE6())
          .putInt(Settings.LON, user.getLongitudeE6())
          .commit();

      setCar(user);

      mListener.onCarMarked(user);

    } else {
      Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
    }
  }
コード例 #3
0
  /**
   * Trys to pan the map to the users location
   *
   * @author ricky barrette
   * @return true if successfull
   */
  private boolean myLocation() {
    mMap.followUser(true);

    /*
     * if we have a gps signal, then pan to user location else notify user
     * that there is no GPS signal
     *
     * we switch from MyLocationOverlay.getMyLocation() to referencing the
     * static variable MyCustomLocationOverlay.gpUser because for some
     * reason getMyLocation() would become null.
     *
     * @author ricky barrette
     */
    if (!panToGeoPoint(mMap.getUserLocation(), true)) {
      Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
      return false;
    } else return true;
  }
コード例 #4
0
  /**
   * Displays the walking directions on the map
   *
   * @author ricky barrette
   */
  private void directions() {
    if (Main.isFull) {
      /*
       * if there is no car marked, then notify user else check to see if
       * there is directions
       */
      if (mCarPoint == null) {
        Toast.makeText(getActivity(), R.string.mark_car_first, Toast.LENGTH_LONG).show();
      } else {

        /*
         * Remove old directions if the exist
         */
        if (mDirections != null) mDirections.removePath();

        /*
         * if there is no location fix then notify user else download
         * directions and display them
         */
        if (mMap.getUserLocation() == null) {
          Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
        } else {

          mProgress =
              ProgressDialog.show(
                  getActivity(), getText(R.string.directions), getText(R.string.calculating), true);
          new Thread(
                  new Runnable() {

                    /**
                     * Notifys user about the error that occurred outside of the UI thread
                     *
                     * @param e
                     * @author ricky barrette
                     */
                    public void notify(final Exception e) {
                      e.printStackTrace();
                      getActivity()
                          .runOnUiThread(
                              new Runnable() {
                                @Override
                                public void run() {
                                  Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG)
                                      .show();
                                  mProgress.dismiss();
                                }
                              });
                    }

                    @Override
                    public void run() {
                      try {
                        mDirections =
                            new DirectionsOverlay(
                                mMap.getMap(), mMap.getUserLocation(), mCarPoint, MapFragment.this);
                      } catch (IllegalStateException e) {
                        notify(e);
                      } catch (ClientProtocolException e) {
                        notify(e);
                      } catch (IOException e) {
                        notify(e);
                      } catch (JSONException e) {
                        notify(e);
                      }
                    }
                  })
              .start();
        }
      }

    } else Main.featureInFullDialog(getActivity());
  }