Example #1
0
  private void updateMapLocation(GeoPoint geoPoint) {
    Log.d(TAG, "updateMapLocation():  ");
    ItemizedOverlay<OverlayItem> locationOverlay;
    ResourceProxy resourceProxy =
        new DefaultResourceProxyImpl(getActivity().getApplicationContext());

    if (geoPoint != null) {
      ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
      items.add(new OverlayItem("Here", "SampleDescription", geoPoint));

      locationOverlay =
          new ItemizedIconOverlay<OverlayItem>(
              items,
              new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
                @Override
                public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                  return true;
                }

                @Override
                public boolean onItemLongPress(final int index, final OverlayItem item) {
                  return false;
                }
              },
              resourceProxy);

      mapView.getOverlays().clear();
      mapView.getOverlays().add(locationOverlay);
      mapView.getController().setCenter(geoPoint);
      mapView.invalidate();
    } else {
      mapView.getOverlays().clear();
      mapView.invalidate();
    }
  }
  private boolean onUp(MotionEvent event, MapView mapView) {
    if (this.onTargetClickListener != null && this.isAClick) {
      this.clickUpCoords[0] = event.getX();
      this.clickUpCoords[1] = event.getY();

      if (Math.abs(this.clickUpCoords[0] - this.clickDownCoords[0]) < 10
          && Math.abs(this.clickUpCoords[1] - this.clickDownCoords[1]) < 10) {
        IGeoPoint igeoPoint =
            mapView.getProjection().fromPixels((int) event.getX(), (int) event.getY());
        GeoPoint geoPoint = new GeoPoint(igeoPoint.getLatitudeE6(), igeoPoint.getLongitudeE6());
        if (event.getEventTime() - this.clickDownTime
                < android.view.ViewConfiguration.getLongPressTimeout()
            && isEventOnTarget(event, mapView)) {
          this.lockPosition = true;
          this.onTargetClickListener.onClick(getMyLocation());
          return true;
        } else if (this.lockPosition == false
            && event.getEventTime() - this.clickDownTime
                >= 0) { // android.view.ViewConfiguration.getP) {
          setLocation(geoPoint);
          mapView.invalidate();
          return true;
        }
      }
      this.isAClick = false;
    }
    return false;
  }
 @Override
 public void onLocationUpdated(GeoPoint currentLoc) {
   if (isPathToBeDisplayed && loadMapTask.isCompleted()) {
     routeTo(destinationNodeId, isWalkOnly, currentLoc, true);
     isPathToBeDisplayed = false;
     destinationNodeId = -1;
     mapView.invalidate();
   }
 }
 /** Clear all schedules on the map */
 public void clearSchedules() {
   randomStudent = null;
   OverlayManager om = mapView.getOverlayManager();
   om.clear();
   scheduleOverlay.clear();
   buildingOverlay.removeAllItems();
   om.addAll(scheduleOverlay);
   om.add(buildingOverlay);
   mapView.invalidate();
 }
 public synchronized void onLocationChanged(Location location) {
   //		Log.i(TAG, "onLocationChanged " +location);
   if (isBetterLocation(location, lastFix)) {
     lastFix = location;
     if (runOnFirstFix != null) {
       runOnFirstFix.run();
       runOnFirstFix = null;
     }
     mapView.invalidate();
   }
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View layout = inflater.inflate(R.layout.fragment_osm_map, container, false);
    map = (MapView) layout.findViewById(R.id.osmmap);
    map.setTileSource(TileSourceFactory.MAPNIK);
    // map.setBuiltInZoomControls(true);
    map.setMultiTouchControls(true);

    // Default location and zoom level
    IMapController mapController = map.getController();
    mapController.setZoom(12);
    GeoPoint startPoint = new GeoPoint(37.4333, 127.1500);
    mapController.setCenter(startPoint);
    // MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(getActivity(), new
    // GpsMyLocationProvider(getActivity()),map);
    // map.getOverlays().add(mLocationOverlay);

    Marker startMarker = new Marker(map);
    startMarker.setPosition(startPoint);
    startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    map.getOverlays().add(startMarker);

    RoadManager roadManager = new OSRMRoadManager(getActivity());
    waypoints = new ArrayList<GeoPoint>();
    waypoints.add(startPoint);
    GeoPoint endPoint = new GeoPoint(37.4314, 127.1297);
    waypoints.add(endPoint);

    Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

    myLocationOverlay = new DirectedLocationOverlay(getActivity());
    map.getOverlays().add(myLocationOverlay);
    myLocationOverlay.setLocation(new GeoPoint(location));
    map.invalidate();

    handler =
        new Handler() {
          @Override
          public void handleMessage(Message msg) {
            GeoPoint geo = (GeoPoint) msg.obj;
            map.getController().animateTo(geo);
            map.invalidate();
          }
        };

    return layout;
  }
 @Override
 protected void onPostExecute(String s) {
   Polyline roadOverlay = RoadManager.buildRoadOverlay(road, context);
   map.getOverlays().add(roadOverlay);
   Drawable nodeIcon = getResources().getDrawable(R.drawable.marker_node);
   for (int i = 0; i < road.mNodes.size(); i++) {
     RoadNode node = road.mNodes.get(i);
     Marker nodeMarker = new Marker(map);
     nodeMarker.setPosition(node.mLocation);
     nodeMarker.setIcon(nodeIcon);
     nodeMarker.setTitle("Step " + i);
     nodeMarker.setSnippet(node.mInstructions);
     nodeMarker.setSubDescription(Road.getLengthDurationText(node.mLength, node.mDuration));
     map.getOverlays().add(nodeMarker);
   }
   map.invalidate();
 }
Example #8
0
  private void updateLocation(String devId) {
    LocationModel lm = LocationModel.getInstance();
    List<Location> locList = lm.getLocations(devId);
    Location prevLoc = null;
    Location currLoc = locList.get(locList.size() - 1);

    if (locList.size() > 1) {
      prevLoc = locList.get(locList.size() - 2);
      GeoPoint p = new GeoPoint(prevLoc.getLatitude(), prevLoc.getLongitude());
      prevLocationsOverlay.addItem(p, prevLoc.getInfo(), prevLoc.getInfo());
    }

    MapView mapView = (MapView) findViewById(R.id.mapview);

    GeoPoint myPoint1 = new GeoPoint(currLoc.getLatitude(), currLoc.getLongitude());
    currLocationOverlay.removeAllItems();
    currLocationOverlay.addItem(myPoint1, currLoc.getInfo(), currLoc.getInfo());

    mapView.getController().setZoom(13);
    mapView.getController().animateTo(myPoint1);
    mapView.invalidate();
  }
Example #9
0
 public void moveToEventPosition(final MotionEvent event, final MapView mapView) {
   final Projection pj = mapView.getProjection();
   mPosition = (GeoPoint) pj.fromPixels((int) event.getX(), (int) event.getY());
   mapView.invalidate();
 }
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  @Override
  public boolean longPressHelper(GeoPoint p) {
    // DO NOTHING FOR NOW:

    // MotionEvent e=null;
    /*  Projection proj = mapView.getProjection();
    //GeoPoint point = (GeoPoint) proj.fromPixels((int) mapView.getX(), (int) mapView.getY());
    proj = mapView.getProjection();

    p = (GeoPoint) proj.fromPixels((int) mapView.getX(), (int) mapView.getY());

    int lat= p.getLatitudeE6();
    int lgn= p.getLongitudeE6();*/

    double lg = p.getLongitude();
    double lt = p.getLatitude();
    // Toast.makeText(this, lat, Toast.LENGTH_SHORT).show();
    Intent i = new Intent(MainActivity.this, FormularioActivity.class);
    String lat2 = (String.valueOf(lg));
    String lgn2 = (String.valueOf(lt));
    i.putExtra("lat", lat2);
    // i.putExtra("lat",lgn2);
    // startActivity(i);
    /*    IMapController mapViewController = mapView.getController();
    mapViewController.setZoom(10);
    mapViewController.setCenter(ROSARIO);*/

    Marker GeoMarker = new Marker(mapView);
    GeoMarker.setPosition(new GeoPoint(lt, lg));
    /*int lat= 30;
    int lng=20;
    startMarker.setPosition(new GeoPoint(lat, lng));*/

    GeoMarker.setIcon(getDrawable(R.drawable.icono));
    GeoMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
    InfoWindow infoWindow =
        new InfoWindow(R.layout.bubble_layout, mapView) {
          @Override
          public void onOpen(Object arg0) {
            LinearLayout layout = (LinearLayout) mView.findViewById(R.id.bubble_layout);
            Button btnMoreInfo = (Button) mView.findViewById(R.id.button);
            TextView txtTitle = (TextView) mView.findViewById(R.id.TV_title);
            TextView txtDescription = (TextView) mView.findViewById(R.id.bubble_description);
            TextView txtSubdescription = (TextView) mView.findViewById(R.id.bubble_subdescription);

            /* txtTitle.setText("Title of my marker");
             txtDescription.setText("Click here to view details!");
             txtSubdescription.setText("You can also edit the subdescription");
            */ layout.setOnClickListener(
                new View.OnClickListener() {
                  public void onClick(View v) {
                    // Override Marker's onClick behaviour here
                  }
                });
          }

          @Override
          public void onClose() {}
        };

    GeoMarker.setInfoWindow(infoWindow);

    GeoMarker.setTitle("Fabrica");
    GeoMarker.setSnippet("chicos");
    mapView.getOverlays().add(GeoMarker);
    mapView.invalidate();

    // Toast.makeText(this, "LONGGGG Tapped", Toast.LENGTH_SHORT).show();

    return false;
  }
  /**
   * @see
   *     http://www.netmite.com/android/mydroid/cupcake/development/samples/Compass/src/com/example/android/compass/CompassActivity.java
   * @see
   *     http://stackoverflow.com/questions/6676377/azimuth-found-with-sensor-type-magnetic-field-much-more-unstable-than-sensor-typ
   * @see http
   *     ://books.google.fr/books?id=c59gCUniP5gC&pg=PA639&lpg=PA639&dq=TYPE_MAGNETIC_FIELD+mapView&source=bl&ots=4wT7sgdYpa&sig=zgNnk9jrZpVfPZRVHtm5kobgiTQ
   *     &hl=fr&sa=X&ei=oy53T9LLD4HB8QOLxMm6DQ&ved=0CD4Q6AEwAg#v=onepage&q=TYPE_MAGNETIC_FIELD%20mapView&f=false
   */
  @Override
  public void onSensorChanged(SensorEvent event) {
    int type = event.sensor.getType();
    // if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
    // if (Log.isLoggable(TAG, Log.DEBUG)) Log.d(TAG, "Could not read SENSOR_STATUS_UNRELIABLE for
    // sennsor " + type);
    // return;
    // }
    float[] data = event.values;
    if (type == Sensor.TYPE_ACCELEROMETER) {
      // alpha is calculated as t / (t + dT)
      // with t, the low-pass filter's time-constant
      // and dT, the event delivery rate
      // final float alpha = 0.9f;
      // gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
      // gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
      // gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];

      acceleration[0] = data[0] - gravity[0];
      acceleration[1] = data[1] - gravity[1];
      acceleration[2] = data[2] - gravity[2];
    } else if (type == Sensor.TYPE_MAGNETIC_FIELD) {
      this.sensorMagneticData = data;
    } else if (type == Sensor.TYPE_ORIENTATION) {
      int oldAzimut = this.azimuth;
      this.azimuth = Math.round(event.values[0]);
      if (oldAzimut != this.azimuth) {
        // TODO
        mapView.invalidate();
      }
      return;
    } else {
      // we should not be here.
      return;
    }
    if (true) {

      float[] matrixRotation = new float[16];
      float[] matrixInclination = new float[16];
      SensorManager.getRotationMatrix(
          matrixRotation, matrixInclination, acceleration, sensorMagneticData);
      // float[] outR = new float[16];
      // SensorManager.remapCoordinateSystem(matrixRotation, SensorManager.AXIS_X,
      // SensorManager.AXIS_Z, outR);
      float[] mOrientation = new float[3];
      SensorManager.getOrientation(matrixRotation, mOrientation);
      // Convert the azimuth to degrees in 0.5 degree resolution.
      int newAzimuth = Math.round(Math.round(Math.toDegrees(mOrientation[0])));
      // Adjust the range: 0 < range <= 360 (from: -180 < range <= 180).
      // newAzimuth = (newAzimuth + 360) % 360;
      // alternative newAzimuth = newAzimuth >= 0 ? newAzimuth : newAzimuth + 360;
      //
      if (azimuth != newAzimuth) {
        azimuth = newAzimuth;
        mapView.invalidate();
      }

      // float incl = SensorManager.getInclination(matrixInclination);

    }
  }