Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #3761 - update map padding sample
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Feb 12, 2016
1 parent ee960ec commit 7b1ad61
Showing 1 changed file with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public void onMapReady(@NonNull MapboxMap mapboxMap) {
mMapboxMap = mapboxMap;
mapboxMap.setStyle(Style.MAPBOX_STREETS);

moveToBangalore();
// toggleGps(true);

int paddingLeft = (int) getResources().getDimension(R.dimen.map_padding_left);
int paddingBottom = (int) getResources().getDimension(R.dimen.map_padding_bottom);
int paddingRight = (int) getResources().getDimension(R.dimen.map_padding_right);
Expand Down Expand Up @@ -107,20 +110,32 @@ public boolean onCreateOptionsMenu(Menu menu) {

private void toggleGps(boolean enable) {
try {
if (mMapboxMap != null) {
// Enable user location
mMapboxMap.setMyLocationEnabled(enable);
// Enable user location
mMapboxMap.setMyLocationEnabled(enable);

TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings();
trackingSettings.setDismissTrackingOnGesture(false);
trackingSettings.setMyLocationTrackingMode(enable ? MyLocationTracking.TRACKING_FOLLOW : MyLocationTracking.TRACKING_NONE);

TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings();
trackingSettings.setDismissTrackingOnGesture(false);
trackingSettings.setMyLocationTrackingMode(enable ? MyLocationTracking.TRACKING_FOLLOW : MyLocationTracking.TRACKING_NONE);
}
} catch (SecurityException e) {
// permission not granted is handled in MainActivity
finish();
}
}

private void moveToBangalore() {
toggleGps(false);
LatLng bangalore = new LatLng(12.9810816, 77.6368034);
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.zoom(16)
.target(bangalore)
.bearing(40)
.tilt(45)
.build()));
mMapboxMap.addMarker(new MarkerOptions().title("Center map").position(bangalore));
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
Expand All @@ -129,22 +144,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;

case R.id.action_user_tracking:
toggleGps(true);
if (mMapboxMap != null) {
toggleGps(true);
}
return true;

case R.id.action_bangalore:
if (mMapboxMap != null) {
// Move to bangalore
toggleGps(false);
LatLng bangalore = new LatLng(12.9810816, 77.6368034);
mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.zoom(16)
.target(bangalore)
.bearing(40)
.tilt(45)
.build()));
mMapboxMap.addMarker(new MarkerOptions().title("Center map").position(bangalore));
moveToBangalore();
}
return true;

Expand Down

0 comments on commit 7b1ad61

Please sign in to comment.