Java Code Examples for org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay#enableMyLocation()

The following examples show how to use org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay#enableMyLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PositionPickerFragment.java    From AsteroidOSSync with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode,
                                       @NonNull String permissions[], @NonNull int[] grantResults) {
    switch (requestCode) {
        case WEATHER_LOCATION_SYNC_PERMISSION_REQUEST: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                handleLocationToggle(mWeatherSyncCheckBox.isChecked());
            } else {
                handleLocationToggle(false);
                mWeatherSyncCheckBox.setChecked(false);
            }
            break;
        }
        case WEATHER_LOCATION_PERMISSION_REQUEST: {
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(getContext()), mMapView);
                mLocationOverlay.enableMyLocation();
                mMapView.getOverlays().add(mLocationOverlay);
            }
        }
    }
}
 
Example 2
Source File: GPSTracker.java    From Travel-Mate with MIT License 5 votes vote down vote up
/**
 * Function to switch GPS on
 */
public void displayLocationRequest(Context context, MapView mapView) {
    MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(context), mapView);
    mLocationOverlay.enableFollowLocation();
    mLocationOverlay.enableMyLocation();
    mapView.getOverlays().add(mLocationOverlay);
}
 
Example 3
Source File: MapViewRealTimeActivity.java    From Travel-Mate with MIT License 5 votes vote down vote up
/**
 * On open street map initialize
 */
private void initMap() {
    mMap.setBuiltInZoomControls(false);
    mMap.setMultiTouchControls(true);
    mMap.setTilesScaledToDpi(true);
    mController = mMap.getController();

    MyLocationNewOverlay mLocationoverlay = new MyLocationNewOverlay(mMap);
    mLocationoverlay.enableFollowLocation();
    mLocationoverlay.enableMyLocation();
    mMap.getOverlays().add(mLocationoverlay);
    mController.setZoom(14.0);
}
 
Example 4
Source File: SampleHeadingCompassUp.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
@Override
public void addOverlays() {
    overlay = new MyLocationNewOverlay(mMapView);
    overlay.setEnableAutoStop(false);
    overlay.enableFollowLocation();
    overlay.enableMyLocation();
    this.mMapView.getOverlayManager().add(overlay);
}
 
Example 5
Source File: WeathForceActivity.java    From osmdroid with Apache License 2.0 5 votes vote down vote up
public void addOverlays() {
    mLocationOverlay = new MyLocationNewOverlay(mMapView);
    mLocationOverlay.setEnableAutoStop(false);
    mLocationOverlay.enableFollowLocation();
    mLocationOverlay.enableMyLocation();
    this.mMapView.getOverlayManager().add(mLocationOverlay);
    mMapView.setMultiTouchControls(true);
    mMapView.setTilesScaledToDpi(true);
}
 
Example 6
Source File: StarterMapFragment.java    From osmdroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final Context context = this.getActivity();
    final DisplayMetrics dm = context.getResources().getDisplayMetrics();

    mPrefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);


    //My Location
    //note you have handle the permissions yourself, the overlay did not do it for you
    mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(context), mMapView);
    mLocationOverlay.enableMyLocation();
    mMapView.getOverlays().add(this.mLocationOverlay);



    //Mini map
    mMinimapOverlay = new MinimapOverlay(context, mMapView.getTileRequestCompleteHandler());
    mMinimapOverlay.setWidth(dm.widthPixels / 5);
    mMinimapOverlay.setHeight(dm.heightPixels / 5);
    mMapView.getOverlays().add(this.mMinimapOverlay);



    //Copyright overlay
    mCopyrightOverlay = new CopyrightOverlay(context);
    //i hate this very much, but it seems as if certain versions of android and/or
    //device types handle screen offsets differently
    mMapView.getOverlays().add(this.mCopyrightOverlay);




    //On screen compass
    mCompassOverlay = new CompassOverlay(context, new InternalCompassOrientationProvider(context),
        mMapView);
    mCompassOverlay.enableCompass();
    mMapView.getOverlays().add(this.mCompassOverlay);


    //map scale
    mScaleBarOverlay = new ScaleBarOverlay(mMapView);
    mScaleBarOverlay.setCentred(true);
    mScaleBarOverlay.setScaleBarOffset(dm.widthPixels / 2, 10);
    mMapView.getOverlays().add(this.mScaleBarOverlay);



    //support for map rotation
    mRotationGestureOverlay = new RotationGestureOverlay(mMapView);
    mRotationGestureOverlay.setEnabled(true);
    mMapView.getOverlays().add(this.mRotationGestureOverlay);


    //needed for pinch zooms
    mMapView.setMultiTouchControls(true);

    //scales tiles to the current screen's DPI, helps with readability of labels
    mMapView.setTilesScaledToDpi(true);

    //the rest of this is restoring the last map location the user looked at
    final float zoomLevel = mPrefs.getFloat(PREFS_ZOOM_LEVEL_DOUBLE, 1);
    mMapView.getController().setZoom(zoomLevel);
    final float orientation = mPrefs.getFloat(PREFS_ORIENTATION, 0);
    mMapView.setMapOrientation(orientation, false);
    final String latitudeString = mPrefs.getString(PREFS_LATITUDE_STRING, "1.0");
    final String longitudeString = mPrefs.getString(PREFS_LONGITUDE_STRING, "1.0");
    final double latitude = Double.valueOf(latitudeString);
    final double longitude = Double.valueOf(longitudeString);
    mMapView.setExpectedCenter(new GeoPoint(latitude, longitude));

    setHasOptionsMenu(true);
}