コード例 #1
0
  /**
   * Enable location updates and show your current location on the map. By default this will request
   * location updates as frequently as possible, but you can change the frequency and/or distance by
   * calling {@link setLocationUpdateMinTime(long)} and/or {@link
   * setLocationUpdateMinDistance(float)} before calling this method. You will want to call
   * enableMyLocation() probably from your Activity's Activity.onResume() method, to enable the
   * features of this overlay. Remember to call the corresponding disableMyLocation() in your
   * Activity's Activity.onPause() method to turn off updates when in the background.
   */
  public boolean enableMyLocation() {
    boolean result = true;

    if (mLocationListener == null) {
      mLocationListener = new LocationListenerProxy(mLocationManager);
      result =
          mLocationListener.startListening(
              this, mLocationUpdateMinTime, mLocationUpdateMinDistance);
    }

    // set initial location when enabled
    if (isFollowLocationEnabled()) {
      mLocation = LocationUtils.getLastKnownLocation(mLocationManager);
      if (mLocation != null) {
        mMapController.animateTo(new GeoPoint(mLocation));
      }
    }

    // Update the screen to see changes take effect
    if (mMapView != null) {
      mMapView.postInvalidate();
    }

    return result;
  }
コード例 #2
0
  /** Disable location updates */
  public void disableMyLocation() {
    if (mLocationListener != null) {
      mLocationListener.stopListening();
    }

    mLocationListener = null;

    // Update the screen to see changes take effect
    if (mMapView != null) {
      mMapView.postInvalidate();
    }
  }