/** * 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; }
/** * Enables "follow" functionality. The map will center on your current location and automatically * scroll as you move. Scrolling the map in the UI will disable. */ public void enableFollowLocation() { mFollow = true; btnFollow.setVisibility(View.GONE); Toast.makeText(thisActivity, "GPS follow mode is ON.", Toast.LENGTH_SHORT).show(); // set initial location when enabled if (isMyLocationEnabled()) { 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(); } }