use of org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider in project collect by opendatakit.
the class GeoShapeOsmMapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.geoshape_osm_layout);
// Setting title of the action
setTitle(getString(R.string.geoshape_title));
ImageButton saveButton = findViewById(R.id.save);
clearButton = findViewById(R.id.clear);
map = findViewById(R.id.geoshape_mapview);
helper = new MapHelper(this, map, this);
map.setMultiTouchControls(true);
map.setBuiltInZoomControls(true);
map.setTilesScaledToDpi(true);
map.setMapListener(mapViewListener);
overlayPointPathListener();
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
returnLocation();
}
});
clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mapMarkers.size() != 0) {
showClearDialog();
}
}
});
ImageButton layersButton = findViewById(R.id.layers);
layersButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
helper.showLayersDialog(GeoShapeOsmMapActivity.this);
}
});
locationButton = findViewById(R.id.gps);
locationButton.setEnabled(false);
locationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
showZoomDialog();
}
});
GpsMyLocationProvider imlp = new GpsMyLocationProvider(this.getBaseContext());
imlp.setLocationUpdateMinDistance(1000);
imlp.setLocationUpdateMinTime(60000);
myLocationOverlay = new MyLocationNewOverlay(map);
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
if (intent.hasExtra(GeoShapeWidget.SHAPE_LOCATION)) {
clearButton.setEnabled(true);
dataLoaded = true;
String s = intent.getStringExtra(GeoShapeWidget.SHAPE_LOCATION);
overlayIntentPolygon(s);
// zoomToCentroid();
locationButton.setEnabled(true);
zoomToBounds();
}
} else {
myLocationOverlay.runOnFirstFix(centerAroundFix);
clearButton.setEnabled(false);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
GeoPoint point = new GeoPoint(34.08145, -39.85007);
map.getController().setZoom(3);
map.getController().setCenter(point);
}
}, 100);
}
map.invalidate();
zoomDialogView = getLayoutInflater().inflate(R.layout.geoshape_zoom_dialog, null);
zoomLocationButton = zoomDialogView.findViewById(R.id.zoom_location);
zoomLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomToMyLocation();
map.invalidate();
zoomDialog.dismiss();
}
});
zoomPointButton = zoomDialogView.findViewById(R.id.zoom_shape);
zoomPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// zoomToCentroid();
zoomToBounds();
map.invalidate();
zoomDialog.dismiss();
}
});
}
use of org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider in project OpenBikeSharing by bparmentier.
the class MapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
getActionBar().setDisplayHomeAsUpEnabled(true);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
stationsDataSource = new StationsDataSource(this);
ArrayList<Station> stations = stationsDataSource.getStations();
map = (MapView) findViewById(R.id.mapView);
stationMarkerInfoWindow = new StationMarkerInfoWindow(R.layout.bonuspack_bubble, map);
/* handling map events */
MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this, this);
map.getOverlays().add(0, mapEventsOverlay);
/* markers list */
GridMarkerClusterer stationsMarkers = new GridMarkerClusterer();
Drawable clusterIconD = getResources().getDrawable(R.drawable.marker_cluster);
Bitmap clusterIcon = ((BitmapDrawable) clusterIconD).getBitmap();
map.getOverlays().add(stationsMarkers);
stationsMarkers.setIcon(clusterIcon);
stationsMarkers.setGridSize(100);
for (final Station station : stations) {
stationsMarkers.add(createStationMarker(station));
}
map.invalidate();
map.setMultiTouchControls(true);
map.setBuiltInZoomControls(true);
map.setMinZoomLevel(3);
/* map tile source */
String mapLayer = settings.getString(PREF_KEY_MAP_LAYER, "");
switch(mapLayer) {
case MAP_LAYER_MAPNIK:
map.setTileSource(TileSourceFactory.MAPNIK);
break;
case MAP_LAYER_CYCLEMAP:
map.setTileSource(TileSourceFactory.CYCLEMAP);
break;
case MAP_LAYER_OSMPUBLICTRANSPORT:
map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);
break;
default:
map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
break;
}
GpsMyLocationProvider imlp = new GpsMyLocationProvider(this.getBaseContext());
imlp.setLocationUpdateMinDistance(1000);
imlp.setLocationUpdateMinTime(60000);
map.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
myLocationOverlay = new MyLocationNewOverlay(imlp, this.map);
myLocationOverlay.enableMyLocation();
map.getOverlays().add(this.myLocationOverlay);
mapController = map.getController();
if (savedInstanceState != null) {
mapController.setZoom(savedInstanceState.getInt(MAP_CURRENT_ZOOM_KEY));
mapController.setCenter(new GeoPoint(savedInstanceState.getDouble(MAP_CENTER_LAT_KEY), savedInstanceState.getDouble(MAP_CENTER_LON_KEY)));
} else {
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Location userLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (userLocation != null) {
mapController.setZoom(16);
mapController.animateTo(new GeoPoint(userLocation));
} else {
double bikeNetworkLatitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LATITUDE, 0));
double bikeNetworkLongitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LONGITUDE, 0));
mapController.setZoom(13);
mapController.setCenter(new GeoPoint(bikeNetworkLatitude, bikeNetworkLongitude));
Toast.makeText(this, R.string.location_not_found, Toast.LENGTH_LONG).show();
}
}
}
use of org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class MapFragment method setUpMapIfNeeded.
/**
* 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);
// Latest OSM can go to 21!
mMap.setMaxZoomLevel(19);
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);
mCellTowerGridMarkerClusterer.setIcon(mapPinDrawable == null ? null : mapPinDrawable.getBitmap());
GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(getActivity().getBaseContext());
// [m] // Set the minimum distance for location updates
gpsMyLocationProvider.setLocationUpdateMinDistance(100);
// [ms] // Set the minimum time interval for location updates
gpsMyLocationProvider.setLocationUpdateMinTime(10000);
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);
}
use of org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class MapViewerOsmDroid method setUpMapIfNeeded.
/**
* 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);
// Latest OSM can go to 21!
mMap.setMaxZoomLevel(19);
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);
mCellTowerGridMarkerClusterer.setIcon(mapPinDrawable == null ? null : mapPinDrawable.getBitmap());
GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(MapViewerOsmDroid.this.getBaseContext());
// [m] // Set the minimum distance for location updates
gpsMyLocationProvider.setLocationUpdateMinDistance(100);
// [ms] // Set the minimum time interval for location updates
gpsMyLocationProvider.setLocationUpdateMinTime(10000);
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);
}
Aggregations