org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider Java Examples
The following examples show how to use
org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider.
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: CreatePoiFragment.java From AndroidApp with Mozilla Public License 2.0 | 6 votes |
private void mapSetup() { map = (MapView) getActivity().findViewById(R.id.createPoiMap); //important! set your user agent to prevent getting banned from the osm servers Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity())); map.setTileSource(TileSourceFactory.MAPNIK); map.setTilesScaledToDpi(true); // add multi-touch capability map.setMultiTouchControls(true); // add compass to map CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map); compassOverlay.enableCompass(); map.getOverlays().add(compassOverlay); // get map controller IMapController controller = map.getController(); GeoPoint position = new GeoPoint(latitude, longitude); controller.setCenter(position); controller.setZoom(18); MapUtils.addMarker(getActivity(), map, latitude, longitude); }
Example #2
Source File: MapFragment.java From AndroidApp with Mozilla Public License 2.0 | 6 votes |
private void mapSetup() { map = (MapView) getActivity().findViewById(R.id.map); // create basic map mController = map.getController(); // get map controller map.setTileSource(TileSourceFactory.MAPNIK); map.setTilesScaledToDpi(true); map.setMultiTouchControls(true); // add compass to map CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map); compassOverlay.enableCompass(); map.getOverlays().add(compassOverlay); //attach listeners MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this); map.getOverlays().add(0, mapEventsOverlay); setupMyLocation(); }
Example #3
Source File: PoiListFragment.java From AndroidApp with Mozilla Public License 2.0 | 6 votes |
/** * Show marker of POI on map preview, on {@link RecyclerView} long press * * @param element POI to display */ private void openMapPreview(Element element) { if (map == null) { //important! set your user agent to prevent getting banned from the osm servers Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity())); map = getActivity().findViewById(R.id.mapPoiList); map.setTileSource(TileSourceFactory.MAPNIK); map.setTilesScaledToDpi(true); // add multi-touch capability map.setMultiTouchControls(true); // add compass to map CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map); compassOverlay.enableCompass(); map.getOverlays().add(compassOverlay); } // get map controller IMapController controller = map.getController(); GeoPoint position = new GeoPoint(element.lat, element.lon); controller.setCenter(position); controller.setZoom(18); MapUtils.addMarker(getActivity(), map, element); }
Example #4
Source File: PoiDetailsFragment.java From AndroidApp with Mozilla Public License 2.0 | 6 votes |
private void setupMapPreview(double lat, double lon, String markerTitle) { //important! set your user agent to prevent getting banned from the osm servers Configuration.getInstance().load(getDialog().getContext(), PreferenceManager.getDefaultSharedPreferences(getDialog().getContext())); map = (MapView) getDialog().findViewById(R.id.poiDialogMap); map.setTileSource(TileSourceFactory.MAPNIK); map.setTilesScaledToDpi(true); map.setMultiTouchControls(true); // add compass to map CompassOverlay compassOverlay = new CompassOverlay(getDialog().getContext(), new InternalCompassOrientationProvider(getDialog().getContext()), map); compassOverlay.enableCompass(); map.getOverlays().add(compassOverlay); // get map controller IMapController controller = map.getController(); GeoPoint position = new GeoPoint(lat, lon); controller.setCenter(position); controller.setZoom(18); MapUtils.addMarker(getActivity(), map, lat, lon, markerTitle); }
Example #5
Source File: EditPoiFragment.java From AndroidApp with Mozilla Public License 2.0 | 6 votes |
private void mapSetup() { map = getActivity().findViewById(R.id.createPoiMap); //important! set your user agent to prevent getting banned from the osm servers Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity())); map.setTileSource(TileSourceFactory.MAPNIK); map.setTilesScaledToDpi(true); map.setMultiTouchControls(true); CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map); compassOverlay.enableCompass(); map.getOverlays().add(compassOverlay); IMapController controller = map.getController(); GeoPoint position = new GeoPoint(POI.getLatitude(), POI.getLongitude()); controller.setCenter(position); controller.setZoom(18); MapUtils.addMarker(getActivity(), map, POI.getLatitude(), POI.getLongitude()); }
Example #6
Source File: MapFragment.java From AIMSICDL with GNU General Public License v3.0 | 5 votes |
/** * 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 #7
Source File: MapViewerOsmDroid.java From AIMSICDL with GNU General Public License v3.0 | 5 votes |
/** * 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 #8
Source File: PoiListFragment.java From AndroidApp with Mozilla Public License 2.0 | 5 votes |
/** * Show all markers of the POIs on the map preview * * @param elements List of POIs to display */ private void setupMapMarkers(List<Element> elements) { //important! set your user agent to prevent getting banned from the osm servers Configuration.getInstance().load(getActivity(), PreferenceManager.getDefaultSharedPreferences(getActivity())); //clear existing markers if (map != null) map.getOverlays().clear(); map = getActivity().findViewById(R.id.mapPoiList); map.setTileSource(TileSourceFactory.MAPNIK); map.setTilesScaledToDpi(true); map.setMultiTouchControls(true); // add compass to map CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map); compassOverlay.enableCompass(); map.getOverlays().add(compassOverlay); // get map controller IMapController controller = map.getController(); for (Element element : elements) MapUtils.addMarker(getActivity(), map, element); if (elements.size() > 0) { GeoPoint position = new GeoPoint(elements.get(0).lat, elements.get(0).lon); controller.setCenter(position); controller.setZoom(14); } setupMyLocation(); }
Example #9
Source File: SampleTester.java From osmdroid with Apache License 2.0 | 5 votes |
protected void addOverlays() { //sorry for the spaghetti code this is to filter out the compass on api 8 //Note: the compass overlay causes issues on API 8 devices. See https://github.com/osmdroid/osmdroid/issues/218 mCompassOverlay = new CompassOverlay(getContext(), new InternalCompassOrientationProvider(getContext()), mMapView); mCompassOverlay.enableCompass(); mMapView.getOverlays().add(this.mCompassOverlay); }
Example #10
Source File: SampleTester.java From osmdroid with Apache License 2.0 | 5 votes |
@Override public void onResume() { super.onResume(); //sorry for the spaghetti code this is to filter out the compass on api 8 //Note: the compass overlay causes issues on API 8 devices. See https://github.com/osmdroid/osmdroid/issues/218 if (mCompassOverlay != null) { //this call is needed because onPause, the orientation provider is destroyed to prevent context leaks this.mCompassOverlay.setOrientationProvider(new InternalCompassOrientationProvider(getActivity())); this.mCompassOverlay.enableCompass(); } }
Example #11
Source File: WeathForceActivity.java From osmdroid with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_starter_mapview); Intent intent = getIntent(); //if (intent) final double lat1 = 25.633; final double long1 = 71.094; //super important. Many tile servers, including open street maps, will BAN applications by user //agent. Do not use the sample application's user agent for your app! Use your own setting, such //as the app id. Configuration.getInstance().setUserAgentValue(getPackageName()); mMapView = findViewById(R.id.mapview); mMapView.setTileSource(TileSourceFactory.MAPNIK); mCompassOverlay = new CompassOverlay(this, new InternalCompassOrientationProvider(this), mMapView); mCompassOverlay.enableCompass(); mMapView.getOverlays().add(this.mCompassOverlay); addOverlays(); GeoPoint startPoint = new GeoPoint(lat1, long1); IMapController mapController = mMapView.getController(); mapController.setZoom(9); mapController.setCenter(startPoint); Marker startMarker = new Marker(mMapView); startMarker.setPosition(startPoint); startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); mMapView.getOverlays().add(startMarker); mMapView.invalidate(); }
Example #12
Source File: StarterMapFragment.java From osmdroid with Apache License 2.0 | 4 votes |
@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); }
Example #13
Source File: WeathForceActivity.java From osmdroid with Apache License 2.0 | 4 votes |
@Override protected void onResume() { super.onResume(); //lock the device in current screen orientation int orientation; int rotation = ((WindowManager) this.getSystemService( Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); switch (rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; this.deviceOrientation = 0; break; case Surface.ROTATION_90: this.deviceOrientation = 90; orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_180: this.deviceOrientation = 180; orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; default: this.deviceOrientation = 270; orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; } this.setRequestedOrientation(orientation); LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); try { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } catch (Exception ex) { } compass = new InternalCompassOrientationProvider(this); compass.startOrientationProvider(this); mMapView.getController().zoomTo(14); }