Esempio n. 1
0
  /** Sets the MapView's initial properties. */
  protected void setupMap() {
    gmap.setMapType(GoogleMap.MAP_TYPE_NONE); // Hide Google tiles
    gmap.setMyLocationEnabled(true);

    // Disable UI components
    UiSettings ui = gmap.getUiSettings();
    ui.setAllGesturesEnabled(true);
    ui.setMyLocationButtonEnabled(true);
    ui.setZoomControlsEnabled(false);

    // Add custom map overlay
    overlay =
        gmap.addGroundOverlay(
            new GroundOverlayOptions()
                .image(BitmapDescriptorFactory.fromResource(R.drawable.map_overlay))
                .positionFromBounds(OVERLAY_BOUNDS)
                .zIndex(1.0f));

    gmap.addPolygon(createMapShade()); // Shade out of bounds areas

    gmap.setOnInfoWindowClickListener(this);

    // Center on Lancaster
    centerOnHome();
  }
    public AccidentViewHolder(final View itemView) {
      super(itemView);
      final Context context = itemView.getContext();
      mPadding = context.getResources().getDimensionPixelSize(R.dimen.content_inset_material);

      mMapView = (MapView) itemView.findViewById(R.id.map_view);
      final int gmsState = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
      if (gmsState == ConnectionResult.SUCCESS) {
        mMapView.onCreate(null);
      }

      // Gets to GoogleMap from the MapView and does initialization stuff
      mGoogleMap = mMapView.getMap();
      mGoogleMap.setMyLocationEnabled(false);
      mGoogleMap.setOnMapLoadedCallback(this);

      final UiSettings uiSettings = mGoogleMap.getUiSettings();
      uiSettings.setMyLocationButtonEnabled(false);
      uiSettings.setAllGesturesEnabled(false);
      uiSettings.setZoomControlsEnabled(false);

      // Needs to call MapsInitializer before doing any CameraUpdateFactory calls
      try {
        MapsInitializer.initialize(context);
      } catch (final Exception e) {
        Log.e(LOG_TAG, "Failed to initialize Google Maps. ", e);
      }

      mTimeView = (TextView) itemView.findViewById(R.id.time);
      mMaxSpeedView = (TextView) itemView.findViewById(R.id.max_speed);
    }
  private void setUpMap() {
    verifyLocationPermission();

    mMap.setOnMapClickListener(this);
    mMap.setOnInfoWindowClickListener(this);

    UiSettings settings = mMap.getUiSettings();
    settings.setAllGesturesEnabled(true);
    settings.setMapToolbarEnabled(false);

    // Use stops location if present, otherwise set a geo point in
    // central Stockholm.
    LatLng latLng;
    int zoom;
    if (mStop.getLocation() != null) {
      latLng = new LatLng(mStop.getLocation().getLatitude(), mStop.getLocation().getLongitude());
      zoom = 16;
    } else {
      latLng = new LatLng(59.325309, 18.069763);
      zoom = 12;
    }

    mMarker =
        mMap.addMarker(
            new MarkerOptions()
                .position(latLng)
                .title(getString(R.string.tap_to_select_this_point))
                .visible(true)
                .draggable(true)
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
    mMarker.showInfoWindow();

    mMap.moveCamera(
        CameraUpdateFactory.newCameraPosition(CameraPosition.fromLatLngZoom(latLng, zoom)));
  }
  private void initMap() {

    mGoogleMap = getMap();
    mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    mGoogleMap.setMyLocationEnabled(true);

    Location location = GpsHelper.getInstancia().getLocation();

    mGoogleMap.moveCamera(
        CameraUpdateFactory.newLatLngZoom(
            location == null
                ? DEFAULT_LAT_LNG
                : new LatLng(location.getLatitude(), location.getLongitude()),
            DEFAULT_ZOOM));

    UiSettings settings = getMap().getUiSettings();
    settings.setMyLocationButtonEnabled(true);
    settings.setCompassEnabled(true);
    settings.setAllGesturesEnabled(true);

    mGoogleMap.setOnMapLongClickListener(
        new OnMapLongClickListener() {

          @Override
          public void onMapLongClick(LatLng point) {

            mGoogleMap.clear();

            marker =
                mGoogleMap.addMarker(
                    new MarkerOptions()
                        .position(point)
                        .title("")
                        .icon(
                            BitmapDescriptorFactory.defaultMarker(
                                BitmapDescriptorFactory.HUE_RED)));
          }
        });
    mGoogleMap.setOnInfoWindowClickListener(this);
  }
Esempio n. 5
0
 @Override
 public void onMapReady(GoogleMap googleMap) {
   mGoogleMap = googleMap;
   mMarkersAdapter = new MarkersAdapter(getActivity(), googleMap);
   mMarkersAdapter.setFeatureMode(mFeatureMode);
   mMarkersAdapter.setFullInfoWindowEnabled(true);
   UiSettings settings = googleMap.getUiSettings();
   settings.setMyLocationButtonEnabled(true);
   settings.setCompassEnabled(true);
   settings.setAllGesturesEnabled(mMapGestureEnabled);
   settings.setMapToolbarEnabled(false);
   googleMap.setOnCameraChangeListener(this);
   googleMap.setOnMarkerClickListener(this);
   googleMap.setInfoWindowAdapter(mMarkersAdapter);
   googleMap.setOnInfoWindowClickListener(this);
   googleMap.setPadding(0, mToolbar.getHeight(), 0, mMapBottomPadding);
   getLoaderManager().initLoader(LOADER_MAP, null, mMapCallback);
   if (mMapLocation != null) {
     googleMap.moveCamera(
         CameraUpdateFactory.newLatLngZoom(
             new LatLng(mMapLocation.getLatitude(), mMapLocation.getLongitude()), DEFAULT_ZOOM));
     mMapLocation = null;
   }
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    view = inflater.inflate(R.layout.recording_fragment, container, false);

    activity = getActivity();
    mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.map);

    map = mapFragment.getMap();
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(mapCenter, 11));

    myLocationMarkerIcon = BitmapDescriptorFactory.fromResource(R.drawable.trip_start);

    // Disable most interaction with the map
    mapUiSettings = map.getUiSettings();
    mapUiSettings.setAllGesturesEnabled(false);
    mapUiSettings.setZoomControlsEnabled(false);

    recordingService = new Intent(activity, RecordingService.class);
    recordingServiceConnection =
        new ServiceConnection() {
          @Override
          public void onServiceConnected(ComponentName name, IBinder binder) {
            Log.i(getClass().getName(), "onServiceConnected");

            recordingServiceInterface =
                ((RecordingService.RecordingServiceBinder) binder).getService();

            updateUI();
            updateMap();
          }

          @Override
          public void onServiceDisconnected(ComponentName name) {
            Log.i(getClass().getName(), "onServiceConnected");
          }
        };

    recordingBroadcastReceiver =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Log.i(getClass().getName(), action);
            updateUI();
          }
        };

    locationBroadcastReceiver =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Log.i(getClass().getName(), action);
            updateMap();
          }
        };

    clickListener =
        new OnClickListener() {
          @Override
          public void onClick(View view) {
            switch (view.getId()) {
              case R.id.start_recording:
                startRecording();
                break;
                // case R.id.resume_recording:
                //	resumeRecording();
                //	break;
                // case R.id.pause_recording:
                //	pauseRecording();
                //	break;
              case R.id.stop_recording:
                stopRecording();
                break;
              case R.id.mark_button:
                makeMark();
                break;
            }
            updateUI();
          }
        };

    startButton = (ImageButton) view.findViewById(R.id.start_recording);
    startButton.setOnClickListener(clickListener);

    // resumeButton = (ImageButton) view.findViewById(R.id.resume_recording);
    // resumeButton.setOnClickListener(clickListener);

    // pauseButton = (ImageButton) view.findViewById(R.id.pause_recording);
    // pauseButton.setOnClickListener(clickListener);

    stopButton = (ImageButton) view.findViewById(R.id.stop_recording);
    stopButton.setOnClickListener(clickListener);

    markButton = (ImageButton) view.findViewById(R.id.mark_button);
    markButton.setOnClickListener(clickListener);

    elapsed_display = (TextView) view.findViewById(R.id.elapsed_display);
    miles_display = (TextView) view.findViewById(R.id.miles_display);
    mph_display = (TextView) view.findViewById(R.id.mph_display);
    co2_display = (TextView) view.findViewById(R.id.co2_display);
    calories_display = (TextView) view.findViewById(R.id.calories_display);

    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));

    return view;
  }