org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay Java Examples

The following examples show how to use org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay. 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: MapFragment.java    From AIMSICDL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Description:     Initialises the Map and sets initial options such as:
 *                      Zoom levels and controls
 *                      Compass
 *                      ScaleBar
 *                      Cluster Pin colors
 *                      Location update settings
 */
private void setUpMapIfNeeded() {

    // Check if we were successful in obtaining the map.
    mMap.setBuiltInZoomControls(true);
    mMap.setMultiTouchControls(true);
    mMap.setMinZoomLevel(3);
    mMap.setMaxZoomLevel(19); // Latest OSM can go to 21!
    mMap.getTileProvider().createTileCache();
    mCompassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), mMap);

    ScaleBarOverlay mScaleBarOverlay = new ScaleBarOverlay(getActivity());
    mScaleBarOverlay.setScaleBarOffset(getResources().getDisplayMetrics().widthPixels / 2, 10);
    mScaleBarOverlay.setCentred(true);

    // Sets cluster pin color
    mCellTowerGridMarkerClusterer = new CellTowerGridMarkerClusterer(getActivity());
    //BitmapDrawable mapPinDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.ic_map_pin_orange);
    BitmapDrawable mapPinDrawable = (BitmapDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.ic_map_pin_orange, null);
    mCellTowerGridMarkerClusterer.setIcon(mapPinDrawable == null ? null : mapPinDrawable.getBitmap());

    GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(getActivity().getBaseContext());
    gpsMyLocationProvider.setLocationUpdateMinDistance(100); // [m]  // Set the minimum distance for location updates
    gpsMyLocationProvider.setLocationUpdateMinTime(10000);   // [ms] // Set the minimum time interval for location updates
    mMyLocationOverlay = new MyLocationNewOverlay(getActivity().getBaseContext(), gpsMyLocationProvider, mMap);
    mMyLocationOverlay.setDrawAccuracyEnabled(true);

    mMap.getOverlays().add(mCellTowerGridMarkerClusterer);
    mMap.getOverlays().add(mMyLocationOverlay);
    mMap.getOverlays().add(mCompassOverlay);
    mMap.getOverlays().add(mScaleBarOverlay);
}
 
Example #3
Source File: MapViewerOsmDroid.java    From AIMSICDL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Description:     Initialises the Map and sets initial options such as:
 * Zoom levels and controls
 * Compass
 * ScaleBar
 * Cluster Pin colors
 * Location update settings
 */
private void setUpMapIfNeeded() {

    // Check if we were successful in obtaining the map.
    mMap.setBuiltInZoomControls(true);
    mMap.setMultiTouchControls(true);
    mMap.setMinZoomLevel(3);
    mMap.setMaxZoomLevel(19); // Latest OSM can go to 21!
    mMap.getTileProvider().createTileCache();
    mCompassOverlay = new CompassOverlay(this, new InternalCompassOrientationProvider(this), mMap);

    ScaleBarOverlay mScaleBarOverlay = new ScaleBarOverlay(this);
    mScaleBarOverlay.setScaleBarOffset(getResources().getDisplayMetrics().widthPixels / 2, 10);
    mScaleBarOverlay.setCentred(true);

    // Sets cluster pin color
    mCellTowerGridMarkerClusterer = new CellTowerGridMarkerClusterer(MapViewerOsmDroid.this);
    //BitmapDrawable mapPinDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.ic_map_pin_orange);
    BitmapDrawable mapPinDrawable = (BitmapDrawable) ResourcesCompat.getDrawable(getResources(),R.drawable.ic_map_pin_orange, null);

    mCellTowerGridMarkerClusterer.setIcon(mapPinDrawable == null ? null : mapPinDrawable.getBitmap());

    GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(MapViewerOsmDroid.this.getBaseContext());
    gpsMyLocationProvider.setLocationUpdateMinDistance(100); // [m]  // Set the minimum distance for location updates
    gpsMyLocationProvider.setLocationUpdateMinTime(10000);   // [ms] // Set the minimum time interval for location updates
    mMyLocationOverlay = new MyLocationNewOverlay(MapViewerOsmDroid.this.getBaseContext(), gpsMyLocationProvider, mMap);
    mMyLocationOverlay.setDrawAccuracyEnabled(true);

    mMap.getOverlays().add(mCellTowerGridMarkerClusterer);
    mMap.getOverlays().add(mMyLocationOverlay);
    mMap.getOverlays().add(mCompassOverlay);
    mMap.getOverlays().add(mScaleBarOverlay);
}
 
Example #4
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 #5
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 #6
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 #7
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 #8
Source File: MapsActivity.java    From Finder with GNU General Public License v3.0 4 votes vote down vote up
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Context ctx = getApplicationContext();
    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
    Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID);

    setContentView(R.layout.activity_open_map);
    SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    map = findViewById(R.id.map2);
    Configuration.getInstance().setTileFileSystemCacheMaxBytes(1024*1024*Long.parseLong(sPref.getString("cache_size", "5")));
    Configuration.getInstance().setTileFileSystemCacheTrimBytes(512*1024*Long.parseLong(sPref.getString("cache_size", "5")));  // trim storage to ~50% from max after oversize limit


    if (sPref.getBoolean("satellite", false)) {
        final MapBoxTileSource tileSource = new MapBoxTileSource();
        tileSource.retrieveAccessToken(this);
        tileSource.retrieveMapBoxMapId(this);
        map.setTileSource(tileSource);
    } else {
        map.setTileSource(TileSourceFactory.MAPNIK);
    }


    map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);
    mapController = map.getController();

    CopyrightOverlay copyOverlay = new CopyrightOverlay(this);
    copyOverlay.setAlignRight(true);
    map.getOverlays().add(copyOverlay);

    ScaleBarOverlay scaleBar= new ScaleBarOverlay(map);
    scaleBar.setUnitsOfMeasure(ScaleBarOverlay.UnitsOfMeasure.metric);
    scaleBar.setScaleBarOffset(getResources().getDisplayMetrics().widthPixels/2, 50);
    scaleBar.setCentred(true);
    map.getOverlays().add(scaleBar);

    GpsMyLocationProvider gpsProvider = new GpsMyLocationProvider(this.getBaseContext());
    MyLocationNewOverlay myLoc = new MyLocationNewOverlay(gpsProvider, map);
    myLoc.setDrawAccuracyEnabled(true);
    map.getOverlays().add(myLoc);

    CompassOverlay compasOver = new CompassOverlay(this.getBaseContext(), map);
    compasOver.enableCompass();
    map.getOverlays().add(compasOver);

    dBase baseConnect = new dBase(this);
    db = baseConnect.getWritableDatabase();

    Intent intent = this.getIntent();
    mapController.setZoom(intent.getDoubleExtra("zoom", 15.0d));
    String act = intent.getAction();
    if (act.equals("track")) {
        track_id = intent.getIntExtra("track_id", 0);
        line = new Polyline(map);
        line.setColor(Color.BLUE);
        line.setInfoWindow(null);  //delete popup label from track
        line.setGeodesic(true);  //draw "true" lines instead simple lines (great circles)
        trackRedraw();
        map.getOverlays().add(line);
    } else {
        String accuracy = intent.getStringExtra("accuracy");
        GeoPoint startPoint = new GeoPoint(intent.getDoubleExtra("lat", 0d), intent.getDoubleExtra("lon", 0d));
        mapController.setCenter(startPoint);
        Marker startMarker = new Marker(map);
        startMarker.setPosition(startPoint);
        startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
        map.getOverlays().add(startMarker);
        startMarker.setTitle(accuracy);
    }

    //receiver to map updating
    LocalBroadcastManager.getInstance(this).registerReceiver(updMap, new IntentFilter("update_map"));
}
 
Example #9
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);
}