/**
   * Enable location updates and show your current location on the map. By default this will request
   * location updates as frequently as possible, but you can change the frequency and/or distance by
   * calling {@link setLocationUpdateMinTime(long)} and/or {@link
   * setLocationUpdateMinDistance(float)} before calling this method. You will want to call
   * enableMyLocation() probably from your Activity's Activity.onResume() method, to enable the
   * features of this overlay. Remember to call the corresponding disableMyLocation() in your
   * Activity's Activity.onPause() method to turn off updates when in the background.
   */
  public boolean enableMyLocation() {
    boolean result = true;

    if (mLocationListener == null) {
      mLocationListener = new LocationListenerProxy(mLocationManager);
      result =
          mLocationListener.startListening(
              this, mLocationUpdateMinTime, mLocationUpdateMinDistance);
    }

    // set initial location when enabled
    if (isFollowLocationEnabled()) {
      mLocation = LocationUtils.getLastKnownLocation(mLocationManager);
      if (mLocation != null) {
        mMapController.animateTo(new GeoPoint(mLocation));
      }
    }

    // Update the screen to see changes take effect
    if (mMapView != null) {
      mMapView.postInvalidate();
    }

    return result;
  }
Exemplo n.º 2
0
 @Override
 public void onRangeTimelineValuesChanged(int minValue, int maxValue, boolean isRangeDefine) {
   seletedRangeActivated = isRangeDefine;
   seletedRangeBeginTimeInMs = timeBeginInMs + minValue * 1000;
   seletedRangeEndTimeInMs = timeBeginInMs + maxValue * 1000;
   mapView.postInvalidate();
 }
 @Override
 public boolean onSingleTapNotHitOverlays() {
   // TODO Auto-generated method stub
   hideBalloonOverlay();
   mapView.postInvalidate();
   return false;
 }
  public void onLocationChanged(final Location location) {
    if (DEBUGMODE) {
      logger.debug("onLocationChanged(" + location + ")");
    }
    // ignore temporary non-gps fix
    if (mIgnorer.shouldIgnore(location.getProvider(), System.currentTimeMillis())) {
      logger.debug("Ignore temporary non-gps location");
      return;
    }

    mLocation = location;
    if (mFollow) {
      mMapController.setCenter(new GeoPoint(location));
    } else {
      mMapView.postInvalidate(); // redraw the my location icon
    }

    for (final Runnable runnable : mRunOnFirstFix) {
      new Thread(runnable).start();
    }
    mRunOnFirstFix.clear();

    sogTxt.setText(
        String.valueOf((double) Math.round(location.getSpeed() * 1.94 * 100) / 100) + "kts | ");
    cogTxt.setText(String.valueOf(location.getBearing()) + "\u00B0 ");
  }
 public void onSensorChanged(final SensorEvent event) {
   if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) {
     if (event.values != null) {
       mAzimuth = event.values[0];
       mMapView.postInvalidate();
     }
   }
 }
 @Override
 protected boolean onSingleTapUpHelper(final int index, final Item item, final MapView mapView) {
   if (this.mFocusItemsOnTap) {
     this.mFocusedItemIndex = index;
     mapView.postInvalidate();
   }
   return this.mOnItemGestureListener.onItemSingleTapUp(index, item);
 }
  /** Disable location updates */
  public void disableMyLocation() {
    if (mLocationListener != null) {
      mLocationListener.stopListening();
    }

    mLocationListener = null;

    // Update the screen to see changes take effect
    if (mMapView != null) {
      mMapView.postInvalidate();
    }
  }
  /** Disable orientation updates */
  public void disableCompass() {
    if (mSensorListener != null) {
      mSensorListener.stopListening();
    }

    // Reset values
    mSensorListener = null;
    mAzimuth = Float.NaN;

    // Update the screen to see changes take effect
    if (mMapView != null) {
      mMapView.postInvalidate();
    }
  }
  /**
   * Enable orientation sensor (compass) updates and show a compass on the map. You will want to
   * call enableCompass() probably from your Activity's Activity.onResume() method, to enable the
   * features of this overlay. Remember to call the corresponding disableCompass() in your
   * Activity's Activity.onPause() method to turn off updates when in the background.
   */
  public boolean enableCompass() {
    boolean result = true;
    if (mSensorListener == null) {
      mSensorListener = new SensorEventListenerProxy(mSensorManager);
      result =
          mSensorListener.startListening(
              this, Sensor.TYPE_ORIENTATION, SensorManager.SENSOR_DELAY_UI);
    }

    // Update the screen to see changes take effect
    if (mMapView != null) {
      mMapView.postInvalidate();
    }

    return result;
  }
  /**
   * Enables "follow" functionality. The map will center on your current location and automatically
   * scroll as you move. Scrolling the map in the UI will disable.
   */
  public void enableFollowLocation() {
    mFollow = true;
    btnFollow.setVisibility(View.GONE);
    Toast.makeText(thisActivity, "GPS follow mode is ON.", Toast.LENGTH_SHORT).show();

    // set initial location when enabled
    if (isMyLocationEnabled()) {
      mLocation = LocationUtils.getLastKnownLocation(mLocationManager);
      if (mLocation != null) {
        mMapController.animateTo(new GeoPoint(mLocation));
      }
    }

    // Update the screen to see changes take effect
    if (mMapView != null) {
      mMapView.postInvalidate();
    }
  }
  private void invalidateCompass() {
    Rect screenRect = mMapView.getProjection().getScreenRect();
    final int frameLeft =
        screenRect.left
            + (mMapView.getWidth() / 2)
            + (int) FloatMath.ceil((mCompassCenterX - mCompassFrameCenterX) * mScale);
    final int frameTop =
        screenRect.top
            + (mMapView.getHeight() / 2)
            + (int) FloatMath.ceil((mCompassCenterY - mCompassFrameCenterY) * mScale);
    final int frameRight =
        screenRect.left
            + (mMapView.getWidth() / 2)
            + (int) FloatMath.ceil((mCompassCenterX + mCompassFrameCenterX) * mScale);
    final int frameBottom =
        screenRect.top
            + (mMapView.getHeight() / 2)
            + (int) FloatMath.ceil((mCompassCenterY + mCompassFrameCenterY) * mScale);

    // Expand by 2 to cover stroke width
    mMapView.postInvalidate(frameLeft - 2, frameTop - 2, frameRight + 2, frameBottom + 2);
  }
Exemplo n.º 12
0
 private void invalidateMapFor(GeoTrack geoTrack) {
   // TODO for GeoPoint
   mapView.postInvalidate();
 }
Exemplo n.º 13
0
  /** Called when the activity is first created. */
  @SuppressWarnings("deprecation")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
      ctx = this;
      acti = this;
      setContentView(R.layout.open_street_map);
      /* location manager */
      currentLocation = null;
      try {
        // Log.e("find location","dsfdsfdsf");
        lm = (LocationManager) ctx.getSystemService(LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        String provider = lm.getBestProvider(criteria, true);
        ll = new MyLocationListener();
        lm.requestLocationUpdates(provider, 0, 0, ll);
      } catch (Exception e) {
      }
      if (!android.provider.Settings.Secure.getString(
              getContentResolver(), android.provider.Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
          .contains("gps")) {
        showDialog(TURN_ON_GPS);
      }
      check = false;
      // show only one photo into map
      Intent intent = getIntent();
      Bundle extract = intent.getExtras();
      if (extract != null) {
        Log.e("OpenStreetMap", "check : " + check);
        check = true;
        path = extract.getString("image-path");
      }
      myOpenMapView = (MapView) findViewById(R.id.openmapview);
      myOpenMapView.setBuiltInZoomControls(true);
      myOpenMapView.setMultiTouchControls(true);
      myMapController = myOpenMapView.getController();
      myMapController.setZoom(16);
      // if (currentLocation != null) myMapController.animateTo(currentLocation);
      btnS = (ImageButton) findViewById(R.id.btnsw);
      btnS.bringToFront();
      btnS.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              Log.e("OpenStreetMap", "check : " + check);
              if (check == true) {
                acti.finish();
                Intent i = new Intent(acti, GalleryMap.class);
                i.putExtra("image-path", path);
                startActivity(i);

              } else {
                PhimpMe.mTabHost.getTabWidget().getChildAt(1).setVisibility(View.GONE);
                PhimpMe.mTabHost.getTabWidget().getChildAt(2).setVisibility(View.VISIBLE);
                PhimpMe.mTabHost.setCurrentTab(2);
              }
            }
          });

      /*
       * Pin photo
       */
      new Thread() {
        public void run() {

          // show only one photo into map

          if (!path.equals("")) {

            Intent intent = getIntent();
            Bundle extract = intent.getExtras();
            if (extract != null && extract.getString("image-path") != null) {
              String path = extract.getString("image-path");

              File f = new File(path);
              ExifInterface exif_data = null;
              geoDegrees _g = null;
              try {
                exif_data = new ExifInterface(f.getAbsolutePath());
                _g = new geoDegrees(exif_data);
                if (_g.isValid()) {

                  try {

                    String la = _g.getLatitude() + "";
                    String lo = _g.getLongitude() + "";
                    int _latitude = (int) (Float.parseFloat(la) * 1000000);
                    int _longitude = (int) (Float.parseFloat(lo) * 1000000);
                    Log.d(
                        "OpenStreetMap ", "Longtitude :" + _longitude + " Latitude :" + _latitude);
                    if ((_latitude != 0) && (_longitude != 0)) {
                      GeoPoint _gp = new GeoPoint(_latitude, _longitude);
                      ExtendedOverlayItem _item =
                          new ExtendedOverlayItem(f.getName(), "", path, _gp, ctx);

                      anotherOverlayItemArray = new ArrayList<ExtendedOverlayItem>();
                      anotherOverlayItemArray.add(_item);
                      ItemizedOverlayWithBubble<ExtendedOverlayItem> anotherItemizedIconOverlay =
                          new ItemizedOverlayWithBubble<ExtendedOverlayItem>(
                              ctx, anotherOverlayItemArray, myOpenMapView);
                      myOpenMapView.getOverlays().add(anotherItemizedIconOverlay);
                      myMapController.animateTo(_gp);
                    }
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                }
              } catch (IOException e) {
                e.printStackTrace();
              } finally {
                exif_data = null;
                _g = null;
              }
            }
          }
          // show all photo in gallery
          else {
            Log.e("Show all", "Openstreetmap");
            String[] projection = {MediaStore.Images.Media.DATA};
            Cursor cursor =
                managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
            int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            for (int i = 0; i < cursor.getCount(); i++) {
              if (cursor.moveToNext()) PhimpMe.filepath.add(cursor.getString(columnIndex));
            }

            int count = PhimpMe.filepath.size();
            Log.d("OpenStreetMap", "number local image :" + count);
            // int num_photos_added = 0;
            if (count > 0) {
              int i;
              for (i = 0; i < PhimpMe.filepath.size(); i++) {
                String imagePath = PhimpMe.filepath.get(i);

                Log.d("OpenStreetMap", "gallery map path photos index :" + i + imagePath);
                File f = new File(imagePath);
                ExifInterface exif_data = null;
                geoDegrees _g = null;
                try {
                  exif_data = new ExifInterface(f.getAbsolutePath());
                  _g = new geoDegrees(exif_data);
                  if (_g.isValid()) {

                    try {

                      String la = _g.getLatitude() + "";
                      String lo = _g.getLongitude() + "";
                      int _latitude = (int) (Float.parseFloat(la) * 1000000);
                      int _longitude = (int) (Float.parseFloat(lo) * 1000000);
                      Log.d(
                          "OpenStreetMap ",
                          "Longtitude :" + _longitude + " Latitude :" + _latitude);
                      if ((_latitude != 0) && (_longitude != 0)) {
                        GeoPoint _gp = new GeoPoint(_latitude, _longitude);
                        ExtendedOverlayItem _item =
                            new ExtendedOverlayItem(f.getName(), "", imagePath, _gp, ctx);

                        anotherOverlayItemArray = new ArrayList<ExtendedOverlayItem>();
                        anotherOverlayItemArray.add(_item);
                        /*ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay
                        = new ItemizedIconOverlay<OverlayItem>(
                        		ctx, anotherOverlayItemArray, myOnItemGestureListener);     */
                        ItemizedOverlayWithBubble<ExtendedOverlayItem> anotherItemizedIconOverlay =
                            new ItemizedOverlayWithBubble<ExtendedOverlayItem>(
                                ctx, anotherOverlayItemArray, myOpenMapView);
                        ;
                        myOpenMapView.getOverlays().add(anotherItemizedIconOverlay);

                        PhimpMe.filepath.remove(i);
                        // num_photos_added++;
                      }
                    } catch (Exception e) {
                      e.printStackTrace();
                    }
                  }
                } catch (IOException e) {
                  e.printStackTrace();
                } finally {
                  exif_data = null;
                  _g = null;
                }
              }
            }
          }
        }
      }.start();
      /*Toast.makeText(OpenStreetMap.this,
      num_photos_added +" photos has been displayed on map",
      Toast.LENGTH_LONG).show();	*/

      // Add Scale Bar
      ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(this);
      myOpenMapView.getOverlays().add(myScaleBarOverlay);

      // Add MyLocationOverlay
      myLocationOverlay = new MyLocationOverlay(this, myOpenMapView);
      myOpenMapView.getOverlays().add(myLocationOverlay);
      myOpenMapView.postInvalidate();

    } catch (UnsupportedOperationException u) {
      AlertDialog.Builder alert_bug = new AlertDialog.Builder(ctx);
      alert_bug.setTitle("Error!");
      alert_bug.setMessage("Sorry! Your device not support this service!");
      alert_bug.show();
    }
  }
Exemplo n.º 14
0
 public void clearExistingPath() {
   pathPointList.clear();
   pathOverlay.setPoints(pathPointList);
   pathIndicatorOverlays.removeAllItems();
   mapView.postInvalidate();
 }
Exemplo n.º 15
0
  ///////////////////// THIS IS TO DISPLAY PATH WHEN A* ALGORITHM DETERMINES THE
  // PATH/////////////////////////////
  public void showPathForEdges(ArrayList<Edge> pathData) {
    if (pathData == null || pathData.size() == 0) return;

    // HERE WE OBTAIN THE POINTS WHICH TOGETHER REPRESENT THE PATH
    pathPointList.clear();
    ArrayList<GeoPoint> edgeContourList;
    int color = 0;
    Edge edge;

    for (int i = (pathData.size() - 1); i >= 0; i--) {
      edge = pathData.get(i);
      color = edge.getEdgeColor();
      pathPointList.add(
          new PathPoint(
              edge.getToNode().getLatE6(),
              edge.getToNode().getLongE6(),
              color)); // this is the destination node's coords

      edgeContourList = edge.getEdgeContourList(mContext.getContentResolver());
      if (edgeContourList != null) {
        for (GeoPoint p : edgeContourList) {
          pathPointList.add(new PathPoint(p.getLatitudeE6(), p.getLongitudeE6(), color));
        }
      }

      if (i == 0) {
        // add the data of the first point of the first node
        pathPointList.add(
            new PathPoint(edge.getFromNode().getLatE6(), edge.getFromNode().getLongE6(), color));
      }
    }

    // HERE WE GET THE PATH INDICATORS LIST
    pathIndicatorList.clear();
    pathIndicatorOverlays.removeAllItems();
    Node n;
    int currentType = Edge.TYPE_WALK;
    Resources r = mapView.getResources();
    int indicatorCount = 0;
    int prevEdgeType = -1;
    String title = "";
    for (int i = 0; i < pathData.size(); i++) {
      try {
        edge = pathData.get(i);

        if (edge.getEdgeType() == Edge.TYPE_WAIT) {
          // special case: if the final destination is a bus/tram stop
          // we add a final indicator for destination node
          if (i == (pathData.size() - 1)) { // last edge. must display destination
            n = edge.getToNode();
            indicatorCount++;
            OverlayItem item =
                new OverlayItem(
                    indicatorCount + ":path_indicator" + n.getID(),
                    null,
                    "Reach destination at " + n.getTitle(),
                    n.getGeoPoint(),
                    DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
            item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
            pathIndicatorOverlays.addItem(item);
            break;
          }

          if (edge.getCostForEdge() > 0) title = edge.getFromNode().getTitle();
          continue;
        }

        if (i == 0) { // first edge. must display start point
          currentType = edge.getEdgeType();
          n = edge.getFromNode();
          if (n.getTitle() != null) title = n.getTitle();
          indicatorCount++;
          String descText = edge.getLineName();
          if (edge.getEdgeType() == Edge.TYPE_WALK) {
            if (edge.getCostForEdge() == Edge.DUMMY_EDGE_COST)
              descText = "Walk from your starting location";
            else descText = descText.replace("Alight", "Start").replace("#NODE_NAME#", title);
          } else {
            descText =
                descText
                    .replace("Board", "Start at " + title + " and board")
                    .replace("#NODE_NAME#", "");
          }

          OverlayItem item =
              new OverlayItem(
                  indicatorCount + ":path_indicator" + n.getID(),
                  null,
                  descText,
                  n.getGeoPoint(),
                  DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
          item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
          pathIndicatorOverlays.addItem(item);
        } else {
          if (edge.getEdgeType() != currentType) {
            // if there is a change in the type of edge
            currentType = edge.getEdgeType();
            n = edge.getFromNode();
            if (n.getTitle() != null) title = n.getTitle();
            indicatorCount++;
            String descText = edge.getLineName();
            if (prevEdgeType != Edge.TYPE_WALK && edge.getEdgeType() != Edge.TYPE_WALK)
              descText = descText.replace("Board", "Alight and change to");
            descText = descText.replace("#NODE_NAME#", title);
            OverlayItem item =
                new OverlayItem(
                    indicatorCount + ":path_indicator" + n.getID(),
                    null,
                    descText,
                    n.getGeoPoint(),
                    DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
            item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
            pathIndicatorOverlays.addItem(item);
          }
        }

        // add a final indicator for destination node
        if (i == (pathData.size() - 1)) { // last edge. must display destination
          n = edge.getToNode();
          indicatorCount++;
          OverlayItem item =
              new OverlayItem(
                  indicatorCount + ":path_indicator" + n.getID(),
                  null,
                  "Reach destination at " + n.getTitle(),
                  n.getGeoPoint(),
                  DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
          item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
          pathIndicatorOverlays.addItem(item);
        }

        prevEdgeType = edge.getEdgeType();
      } catch (Exception ignore) {
        ignore.printStackTrace();
      }
    }

    pathOverlay.setPoints(pathPointList);
    mapView.postInvalidate();
  }