@Override
  public void onNavigationDrawerItemSelected(int position) {
    if (position == lastPosition) {
      return;
    }
    lastPosition = position;

    FragmentManager fragmentManager = getFragmentManager();
    if (position == 0) {
      activeFragment = TrackTrailFragment.newInstance();
      fragmentManager.beginTransaction().replace(R.id.container, activeFragment).commit();
    } else if (position == 1) {
      activeFragment = fragmentManager.findFragmentByTag(TAG_TRACING_FRAGMENT);
      if (activeFragment == null) {
        activeFragment = TraceTrailFragment.newInstance();
      }
      fragmentManager
          .beginTransaction()
          .replace(R.id.container, activeFragment, TAG_TRACING_FRAGMENT)
          .addToBackStack(TAG_TRACING_FRAGMENT)
          .commit();
    } else if (position == 3) {
      activeFragment = new ResultsFragment();
      fragmentManager
          .beginTransaction()
          .replace(R.id.container, activeFragment, TAG_RESULTS_FRAGMENT)
          .commit();
    } else {
      activeFragment = new PlainMapFragment();
      fragmentManager = getFragmentManager();
      fragmentManager.beginTransaction().replace(R.id.container, activeFragment).commit();
    }
    onSectionAttached(position + 1);
  }
 public void onLocationReceived(Location loc, ArrayList<LatLng> trail, long lastLocId) {
   if (activeFragment instanceof TrackTrailFragment) {
     ((TrackTrailFragment) activeFragment).onLocationChanged(loc, trail, lastLocId);
   }
   if (activeFragment instanceof TraceTrailFragment) {
     ((TraceTrailFragment) activeFragment).onLocationChanged(loc);
   }
 }
 @Override
 public void onServiceConnected(ComponentName name, IBinder service) {
   Log.d("ServiceConnection onServiceConnected()", "called");
   binder = (TrailTrackingService.TTBinder) service;
   binder.setLocationListener(MainActivity.this);
   if (activeFragment instanceof TrackTrailFragment) {
     ((TrackTrailFragment) activeFragment).onLocationServiceBound();
   }
   if (activeFragment instanceof TraceTrailFragment) {
     ((TraceTrailFragment) activeFragment).onLocationServiceBound();
   }
   isBoundToLocationService = true;
 }