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();
  }
  /**
   * This is where we can add markers or lines, add listeners or move the camera. In this case, we
   * just add a marker near Africa.
   *
   * <p>This should only be called once and when we are sure that {@link #mMap} is not null.
   */
  private void setUpMap() {

    // app behavior when the app first starts up
    // centers the map at the SJSU campus
    LatLng SJSU = new LatLng(37.3351874, -121.8810715);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(SJSU, 6));
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(SJSU, 18));

    // Click Listeners

    // Button button4 = (Button) findViewById(R.id.TxButton);
    Button button5 = (Button) findViewById(R.id.clearButton);
    button5.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            // Clear all markers on screen
            mMap.clear();
          }
        });

    // need to work on getting a location value

    // UI settings are added here
    UiSettings uiValue = mMap.getUiSettings();
    uiValue.setZoomControlsEnabled(true);
    uiValue.setMyLocationButtonEnabled(true); // only works if mMap.setLocationEnabled(true)
    uiValue.setCompassEnabled(true); // also doesn't seem to work
  }
    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);
    }
 public void showMyLocationButton() {
   if (googleMap != null) {
     UiSettings uiSettings = googleMap.getUiSettings();
     googleMap.setMyLocationEnabled(true);
     uiSettings.setMyLocationButtonEnabled(true);
   }
 }
  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)));
  }
Esempio n. 6
0
 @Override
 public void onMapReady(GoogleMap map) {
   // Add settings to map fragment
   mMap.setMyLocationEnabled(true);
   mMap.setOnMapClickListener(this);
   UiSettings uiSettings = map.getUiSettings();
   uiSettings.setZoomControlsEnabled(true);
 }
 private void setupMapUI() {
   GoogleMap mMap = getMap();
   if (mMap != null) {
     mMap.setMyLocationEnabled(true);
     UiSettings mUiSettings = mMap.getUiSettings();
     mUiSettings.setMyLocationButtonEnabled(true);
     mUiSettings.setCompassEnabled(true);
     mUiSettings.setTiltGesturesEnabled(false);
   }
 }
    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View view = super.onCreateView(inflater, container, savedInstanceState);
      UiSettings settings = getMap().getUiSettings();
      // settings.setAllGesturesEnabled(false);
      settings.setMyLocationButtonEnabled(true);
      settings.setZoomControlsEnabled(false);

      setUpMapIfNeeded();

      return view;
    }
 public void disableGestures() {
   UiSettings uiSettings = googleMap.getUiSettings();
   uiSettings.setMyLocationButtonEnabled(false);
   uiSettings.setTiltGesturesEnabled(false);
   uiSettings.setZoomGesturesEnabled(false);
   uiSettings.setZoomControlsEnabled(false);
   uiSettings.setRotateGesturesEnabled(false);
   uiSettings.setMyLocationButtonEnabled(false);
   uiSettings.setScrollGesturesEnabled(false);
   uiSettings.setCompassEnabled(false);
 }
Esempio n. 10
0
  @Override
  public void onMapReady(GoogleMap googleMap) {
    // Enable MyLocation Button in the Map
    mGoogleMap = googleMap;
    mGoogleMap.setMyLocationEnabled(true);
    mGoogleMap.setBuildingsEnabled(true);

    mGoogleMap.setPadding(0, topPadding, 0, UIUtils.getActionBarSize(this));
    //        mGoogleMap.setOnMarkerClickListener(this);
    //        mGoogleMap.setOnMapClickListener(this);

    UiSettings uiSettings = mGoogleMap.getUiSettings();
    uiSettings.setCompassEnabled(false);
    uiSettings.setTiltGesturesEnabled(false);
    uiSettings.setZoomControlsEnabled(true);
  }
Esempio n. 11
0
 // UI settings of map
 private void mapUiSetting(boolean flag) {
   uiSettings.setZoomControlsEnabled(flag);
   uiSettings.setCompassEnabled(flag);
   uiSettings.setMyLocationButtonEnabled(flag);
   uiSettings.setScrollGesturesEnabled(flag);
   uiSettings.setZoomGesturesEnabled(flag);
   uiSettings.setTiltGesturesEnabled(flag);
   uiSettings.setRotateGesturesEnabled(flag);
 }
  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. 13
0
  /**
   * This is where we can add markers or lines, add listeners or move the camera.
   *
   * <p>This should only be called once and when we are sure that {@link #mMap} is not null.
   */
  private void setUpMap() {

    mapUI = mMap.getUiSettings();
    mapUI.setZoomControlsEnabled(false);

    Intent viewRouteActivity = getIntent();

    this.routeID = Integer.valueOf(viewRouteActivity.getStringExtra("routeID"));
    this.totalDistance = Float.valueOf(viewRouteActivity.getStringExtra("totalDistance"));
    this.avgSpeed = Float.valueOf(viewRouteActivity.getStringExtra("avgSpeed"));
    this.startTime = viewRouteActivity.getStringExtra("startTime");
    this.endtime = viewRouteActivity.getStringExtra("endTime");

    Cursor resultSet = dbHandler.getRoutePoints(this.routeID);

    if (resultSet != null && resultSet.moveToFirst()) {
      PolylineOptions rectOptions = new PolylineOptions().color(Color.BLUE).width(ROUTEWIDTH);

      LatLng routeStart = new LatLng(resultSet.getDouble(LATITUDE), resultSet.getDouble(LONGITUDE));

      LatLng routeEnd = null;

      while (!resultSet.isAfterLast()) {
        rectOptions.add(
            routeEnd = new LatLng(resultSet.getDouble(LATITUDE), resultSet.getDouble(LONGITUDE)));

        resultSet.moveToNext();
      }

      mMap.addPolyline(rectOptions);

      mMap.addMarker(
          new MarkerOptions()
              .position(routeStart)
              .icon(BitmapDescriptorFactory.fromResource(R.drawable.cycling))
              .title(this.startTime));

      mMap.addMarker(
          new MarkerOptions()
              .position(routeEnd)
              .icon(BitmapDescriptorFactory.fromResource(R.drawable.finish))
              .title(this.endtime));

      moveCamera(routeStart, DEFAULTZOOM);

      resultSet.close();
    } else {
      // TODO: some error, no route points for route
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_maps, container, false);
    setUpMapIfNeeded();
    if (savedInstanceState != null) {
      mMap.getCameraPosition();
      //  mMap = savedInstanceState.get   ///getInt(KEY_QUOTE_INDEX);
    }
    mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
    UiSettings uiSettings = mMap.getUiSettings();
    uiSettings.setZoomControlsEnabled(true);
    mMap.setMyLocationEnabled(true);
    uiSettings.setMapToolbarEnabled(true);
    //  CustomMapFragment mapFragment = new CustomMapFragment();
    // FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    // transaction.add(R.id.map_container, mapFragment).commit();
    return rootView;
    //
    // changes the map from street to view to satellite.

  }
Esempio n. 15
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;
   }
 }
Esempio n. 16
0
  /**
   * Manipulates the map once available. This callback is triggered when the map is ready to be
   * used. This is where we can add markers or lines, add listeners or move the camera. In this
   * case, we just add a marker near Sydney, Australia. If Google Play services is not installed on
   * the device, the user will be prompted to install it inside the SupportMapFragment. This method
   * will only be triggered once the user has installed Google Play services and returned to the
   * app.
   */
  @Override
  public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    // mMap.setMyLocationEnabled(true);
    mMap.setBuildingsEnabled(true);
    mMap.setTrafficEnabled(true);

    UiSettings gmapsettings = mMap.getUiSettings();
    gmapsettings.setMyLocationButtonEnabled(true);
    gmapsettings.setCompassEnabled(true);
    gmapsettings.setZoomControlsEnabled(true);
    gmapsettings.setZoomControlsEnabled(true);
    gmapsettings.setScrollGesturesEnabled(true);
    gmapsettings.setRotateGesturesEnabled(true);

    Intent ri = getIntent();
    Bundle a = ri.getExtras();
    String start = a.getString("start");
    String end = a.getString("end");

    Geocoder geocoder = new Geocoder(this);
    List<Address> addresses = null;
    try {
      addresses = geocoder.getFromLocationName(start, 1);
    } catch (IOException e) {
      e.printStackTrace();
    }

    double slatitude = addresses.get(0).getLatitude();
    double slongitude = addresses.get(0).getLongitude();

    // Add a marker to start
    LatLng smarker = new LatLng(slatitude, slongitude);
    mMap.addMarker(
        new MarkerOptions()
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.markers1))
            .position(smarker)
            .title("Pick Up"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(smarker));

    try {
      addresses = geocoder.getFromLocationName(end, 1);
    } catch (IOException e) {
      e.printStackTrace();
    }

    double elatitude = addresses.get(0).getLatitude();
    double elongitude = addresses.get(0).getLongitude();

    // Add a marker to end
    LatLng emarker = new LatLng(elatitude, elongitude);
    mMap.addMarker(
        new MarkerOptions()
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.markers2))
            .position(emarker)
            .title("Destination"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(emarker));

    LatLng origin = smarker;
    LatLng dest = emarker;

    // Getting URL to the Google Directions API
    String url = getDirectionsUrl(origin, dest);

    DownloadTask downloadTask = new DownloadTask();

    // Start downloading json data from Google Directions API
    downloadTask.execute(url);

    mMap.animateCamera(CameraUpdateFactory.newLatLng(smarker));
  }
  @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;
  }