@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        onBackPressed();
        return true;

      case R.id.action_zoom_in:
        mapboxMap.animateCamera(CameraUpdateFactory.zoomIn());
        return true;

      case R.id.action_zoom_out:
        mapboxMap.animateCamera(CameraUpdateFactory.zoomOut());
        return true;

      case R.id.action_zoom_by:
        mapboxMap.animateCamera(CameraUpdateFactory.zoomBy(2));
        return true;
      case R.id.action_zoom_to:
        mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(2));
        return true;

      case R.id.action_zoom_to_point:
        View view = getWindow().getDecorView();
        mapboxMap.animateCamera(
            CameraUpdateFactory.zoomBy(
                1, new Point(view.getMeasuredWidth() / 4, view.getMeasuredHeight() / 4)));
        return true;

      default:
        return super.onOptionsItemSelected(item);
    }
  }
 @Override
 public void onLocationChanged(Location location) {
   if (mapboxMap != null && firstRun) {
     mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location), 15));
     firstRun = false;
   }
 }
    @Override
    void updateLatLng(@NonNull Location location) {
      if (latLng == null) {
        // first location fix
        latLng = new LatLng(location);
        locationUpdateTimestamp = SystemClock.elapsedRealtime();
      }

      // updateLatLng timestamp
      long previousUpdateTimeStamp = locationUpdateTimestamp;
      locationUpdateTimestamp = SystemClock.elapsedRealtime();

      // calculate animation duration
      long locationUpdateDuration;
      if (previousUpdateTimeStamp == 0) {
        locationUpdateDuration = 0;
      } else {
        // TODO remove 10 * hack to multiply duration to workaround easing interpolation
        // (easeCamera)
        locationUpdateDuration = 10 * (locationUpdateTimestamp - previousUpdateTimeStamp);
      }

      // calculate interpolated location
      previousLocation = latLng;
      latLng = new LatLng(location);
      interpolatedLocation =
          new LatLng(
              (latLng.getLatitude() + previousLocation.getLatitude()) / 2,
              (latLng.getLongitude() + previousLocation.getLongitude()) / 2);

      // build new camera
      CameraPosition.Builder builder = new CameraPosition.Builder().target(interpolatedLocation);

      // add direction
      if (myBearingTrackingMode == MyBearingTracking.GPS) {
        if (location.hasBearing()) {
          builder.bearing(location.getBearing());
          gpsDirection = 0;
        }
      } else if (myBearingTrackingMode == MyBearingTracking.COMPASS) {
        if (!compassListener.isPaused()) {
          builder.bearing(compassListener.getCurrentDegree());
          compassDirection = 0;
        }
      }

      updateAccuracy(location);

      // animate to new camera
      mapboxMap.easeCamera(
          CameraUpdateFactory.newCameraPosition(builder.build()),
          (int) locationUpdateDuration,
          null);
    }
  public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
    this.myLocationTrackingMode = myLocationTrackingMode;

    MyLocationBehaviorFactory factory = new MyLocationBehaviorFactory();
    myLocationBehavior = factory.getBehavioralModel(myLocationTrackingMode);

    if (myLocationTrackingMode != MyLocationTracking.TRACKING_NONE && location != null) {
      // center map directly if we have a location fix
      myLocationBehavior.updateLatLng(location);
      mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(location)));
    }
    invalidate();
    update();
  }
 private void enableLocation(boolean enabled) {
   if (enabled) {
     mapboxMap.setMyLocationEnabled(true);
     if (mapboxMap.getMyLocation() != null) {
       mapboxMap.moveCamera(
           CameraUpdateFactory.newLatLngZoom(
               new LatLng(
                   mapboxMap.getMyLocation().getLatitude(),
                   mapboxMap.getMyLocation().getLongitude()),
               15));
     }
   } else {
     mapboxMap.setMyLocationEnabled(false);
   }
 }