コード例 #1
0
ファイル: PlaceView.java プロジェクト: ocrenaka/around_me
 public void onSensorChanged(SensorEvent sensorevent) {
   Location location = new Location("");
   double d = WebUtil.getCurLat();
   double d1 = WebUtil.getCurLog();
   location.setLatitude(d);
   location.setLongitude(d1);
   Location location1 = new Location("");
   location1.setLatitude(place.getLatitude());
   location1.setLongitude(place.getLongitude());
   if (!WebUtil.isLocationSet()) {
     Log.d("test", "NullReturn");
     return;
   }
   float f = sensorevent.values[0];
   float f1 =
       f
           - (new GeomagneticField(
                   Double.valueOf(location.getLatitude()).floatValue(),
                   Double.valueOf(location.getLongitude()).floatValue(),
                   Double.valueOf(location.getAltitude()).floatValue(),
                   System.currentTimeMillis()))
               .getDeclination();
   float f2 = location.bearingTo(location1);
   if (f2 < 0.0F) {
     f2 += 360F;
   }
   float f3 = f2 - f1;
   if (f3 < 0.0F) {
     f3 += 360F;
   }
   rotateImageView(imageCompass, 0x7f0200bb, f3);
   if (360F >= f && (double) f >= 337.5D || 0.0F <= f && (double) f <= 22.5D) {
     return;
   }
   if ((double) f > 22.5D && (double) f < 67.5D) {
     return;
   }
   if ((double) f >= 67.5D && (double) f <= 112.5D) {
     return;
   }
   if ((double) f > 112.5D && (double) f < 157.5D) {
     return;
   }
   if ((double) f >= 157.5D && (double) f <= 202.5D) {
     return;
   }
   if ((double) f > 202.5D && (double) f < 247.5D) {
     return;
   }
   if ((double) f >= 247.5D && (double) f <= 292.5D) {
     return;
   }
   if ((double) f > 292.5D && (double) f < 337.5D) {
     return;
   } else {
     return;
   }
 }
コード例 #2
0
  public static final float getSpotAngle(Context _context, GeoPoint p, Location _me) {
    Location location = new Location("LOCATION_SERVICE");

    try {
      location.setLatitude(p.getLatitudeE6());
      location.setLongitude(p.getLatitudeE6());
    } catch (Exception e) {
    }
    return _me.bearingTo(location);
  }
コード例 #3
0
ファイル: MockEngine.java プロジェクト: dhiyaulhaqZA/LOST
    private Location nodeToLocation(NodeList nodeList, NodeList speedList, int i) {
      final Node node = nodeList.item(i);
      String lat = node.getAttributes().getNamedItem(TAG_LAT).getNodeValue();
      String lng = node.getAttributes().getNamedItem(TAG_LNG).getNodeValue();

      final Location location = new Location(MOCK_PROVIDER);
      location.setLatitude(Double.parseDouble(lat));
      location.setLongitude(Double.parseDouble(lng));
      location.setTime(System.currentTimeMillis());
      location.setSpeed(Float.parseFloat(speedList.item(i).getFirstChild().getNodeValue()));

      if (previous != null) {
        location.setBearing(previous.bearingTo(location));
      }

      previous = location;
      return location;
    }
コード例 #4
0
  @Override
  protected void onPostExecute(String placesResponse) {
    try {
      JSONObject placeResponseObject = new JSONObject(placesResponse);
      JSONArray placeArray = placeResponseObject.getJSONArray("results");
      String NamesByDistance = "";
      for (int i = 0; i < placeArray.length(); i++) {

        JSONObject place = placeArray.getJSONObject(i);
        JSONObject geo = place.getJSONObject("geometry").getJSONObject("location");
        Location tempLoc = new Location("dummyprovider");

        Double lati = Double.parseDouble(geo.getString("lat"));
        Double longi = Double.parseDouble(geo.getString("lng"));

        String tempName = place.getString("name");

        tempLoc.setLatitude(lati);
        tempLoc.setLongitude(longi);
        float distance = location.distanceTo(tempLoc);
        Place p = new Place(tempLoc, tempName, distance);

        if (placeList.contains(p)) {
          placeList.get(placeList.indexOf(p)).setDistance(distance);
        } else {
          placeList.add(p);
        }
      }
      Collections.sort(placeList);
      for (Place p : placeList) {
        String s = p.name + ": " + p.distanceTo + "m " + location.bearingTo(p.loc) + "\n";
        NamesByDistance += s;
      }
      System.out.println(placeList.get(0).name);
      delegate.onProcessFinish(placeList, lastJSONResponse);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #5
0
  @Override
  public void onLocationChanged(Location location) {
    mLastLocation = location;
    if (mStopLocation != null) {
      if (!mInitialized) {
        mInitialized = true;
        // Notify listeners that we have both stop and real-time location and can draw
        for (Listener l : mListeners) {
          l.onInitializationComplete();
        }
      }

      mBearingToStop = location.bearingTo(mStopLocation);

      // Result of bearingTo() can be from -180 to 180. If negative, convert to 181-360 range
      // See http://stackoverflow.com/a/8043485/937715
      if (mBearingToStop < 0) {
        mBearingToStop += 360;
      }
      invalidate();
    }
  }
コード例 #6
0
ファイル: POI.java プロジェクト: cyc115/rter-android-app
 public float relativeBearingTo(Location fromLoc) { // bearing relative to user position
   return minDegreeDelta(fromLoc.bearingTo(loc), mSensorSource.getCurrentOrientation());
 }
コード例 #7
0
ファイル: POI.java プロジェクト: cyc115/rter-android-app
 public float bearingTo(Location fromLoc) {
   return fromLoc.bearingTo(loc);
 }
コード例 #8
0
 public static float bearingBetweenLatLngs(LatLng begin, LatLng end) {
   Location beginL = convertLatLngToLocation(begin);
   Location endL = convertLatLngToLocation(end);
   return beginL.bearingTo(endL);
 }
コード例 #9
0
  private void updateMap() {
    if (map == null) {
      return;
    }
    Station station = Db.get().getStop(adapter.getStops().get(0).id);
    LatLng ll =
        new LatLng(Double.parseDouble(station.getLat()), Double.parseDouble(station.getLng()));
    PolylineOptions poly = new PolylineOptions();
    LatLngBounds llb = new LatLngBounds(ll, ll);
    // map.setMapType(GoogleMap.MAP_TYPE_NONE);
    int dimen = (int) getResources().getDimension(R.dimen.fab_size_mini) / 3;
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    int color = Color.RED;
    Bitmap bitmap = Bitmap.createBitmap(dimen, dimen, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    Station stationA = null, stationB = null;
    Calendar now = Calendar.getInstance();

    TripInfo.Stop previous = null;
    float percent = 0;
    for (TripInfo.Stop stop : adapter.getStops()) {

      canvas.clipRect(0, 0, canvas.getWidth(), canvas.getHeight());
      station = Db.get().getStop(stop.id);
      Log.d(
          TAG,
          station.getName()
              + " "
              + station.getLat()
              + ","
              + station.getLng()
              + " "
              + stop.depart.getTime());
      paint.setColor(color);

      if (now.after(stop.depart)) {
        stationA = station;
        previous = stop;
      } else {
        if (stationB == null && stationA != station) {
          stationB = station;
          if (previous == null) {
            percent = 0;
          } else if (previous.depart == null || stop.arrive == null) {

          } else {
            long max = stop.arrive.getTimeInMillis() - previous.depart.getTimeInMillis();
            long curr = stop.arrive.getTimeInMillis() - System.currentTimeMillis();

            if (curr <= 0) {
              percent = 0;
            } else {
              percent = 1 - (curr / (float) max);
            }
          }
        }
      }
      canvas.drawCircle(
          bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
      station = Db.get().getStop(stop.id);
      LatLng latLng =
          new LatLng(Double.parseDouble(station.getLat()), Double.parseDouble(station.getLng()));
      llb = llb.including(latLng);

      if (markers.get(stop) != null) {
        markers.get(stop).remove();
      }
      Marker hamburg =
          map.addMarker(
              new MarkerOptions()
                  .position(latLng)
                  .anchor(0.5f, 0.5f)
                  .icon(BitmapDescriptorFactory.fromBitmap(bitmap)));
      markers.put(stop, hamburg);
      poly.add(latLng);
    }

    if (polyline != null) {
      polyline.remove();
    } else {
      map.moveCamera(CameraUpdateFactory.newLatLngBounds(llb, dimen));
    }
    // poly.
    polyline = map.addPolyline(poly);

    if (stationA == null) {
      return;
    }
    if (stationB == null) {
      stationB = stationA;
    }

    Location location = new Location(LocationManager.GPS_PROVIDER);
    location.setLatitude(Double.parseDouble(stationA.getLat()));
    location.setLongitude(Double.parseDouble(stationA.getLng()));

    Location location2 = new Location(LocationManager.GPS_PROVIDER);
    location2.setLatitude(Double.parseDouble(stationB.getLat()));
    location2.setLongitude(Double.parseDouble(stationB.getLng()));
    //        var θ = Number(brng).toRadians();
    //        var δ = Number(dist) / this.radius; // angular distance in radians
    //
    //        var φ1 = this.lat.toRadians();
    //        var λ1 = this.lon.toRadians();
    //
    //        var φ2 = Math.asin( Math.sin(φ1)*Math.cos(δ) +
    //                Math.cos(φ1)*Math.sin(δ)*Math.cos(θ) );
    //        var λ2 = λ1 + Math.atan2(Math.sin(θ)*Math.sin(δ)*Math.cos(φ1),
    //                Math.cos(δ)-Math.sin(φ1)*Math.sin(φ2));
    //        λ2 = (λ2+3*Math.PI) % (2*Math.PI) - Math.PI; // normalise to -180..+180°

    double totalDist = location.distanceTo(location2);

    Log.d(TAG, "distance is " + totalDist + " percentage is " + percent);

    double dist = (percent * totalDist) / (6371.0 * 1000.0);

    double brng = Math.toRadians(location.bearingTo(location2));
    double lat1 = Math.toRadians(location.getLatitude());
    double lon1 = Math.toRadians(location.getLongitude());

    double lat2 =
        Math.asin(
            Math.sin(lat1) * Math.cos(dist) + Math.cos(lat1) * Math.sin(dist) * Math.cos(brng));
    double a =
        Math.atan2(
            Math.sin(brng) * Math.sin(dist) * Math.cos(lat1),
            Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2));
    System.out.println("a = " + a);
    double lon2 = lon1 + a;

    lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI;

    System.out.println(
        "Latitude = " + Math.toDegrees(lat2) + "\nLongitude = " + Math.toDegrees(lon2));
    MarkerOptions o =
        new MarkerOptions()
            .anchor(0.5f, 0.5f)
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.new_blue_dot))
            .position(new LatLng(Math.toDegrees(lat2), Math.toDegrees(lon2)));
    if (me != null) {
      me.remove();
    }
    if (stationA != stationB) {
      me = map.addMarker(o);
    }
    Log.d(TAG, "new coordinates are " + lat2 + "," + lon2);
  }
コード例 #10
0
ファイル: ARLayout.java プロジェクト: dotfeng/Android
  public void updateLayouts(float Azi, float zAngle, Location l) {
    /*
    if(l.hasAccuracy()) this.gpsIcon.disconnect();
    else gpsIcon.update(l.getAccuracy());
    */
    if (Azi != -1) {
      // Process the accelerometor stuff
      // Manages mobile orientation
      float leftArm = Azi - (xAngleWidth / 2);
      float rightArm = Azi + (xAngleWidth / 2);
      if (leftArm < 0) leftArm = leftArm + 360;
      if (rightArm > 360) rightArm = rightArm - 360;

      if (this.curLeftArm == -1) this.curLeftArm = leftArm;
      if (this.curRightArm == -1) this.curRightArm = rightArm;

      if (!(aChanger(curLeftArm, leftArm, (float) 0.05))) leftArm = this.curLeftArm;
      else this.curLeftArm = leftArm;
      if (!(aChanger(this.curRightArm, rightArm, (float) 0.05))) rightArm = this.curRightArm;
      else this.curRightArm = rightArm;

      if (leftArm < 0) leftArm = leftArm + 360;
      if (rightArm > 360) rightArm = rightArm - 360;

      // gere l'orientation du mobile en hauteur
      float upperArm = zAngle + (yAngleWidth / 2);
      float lowerArm = zAngle - (yAngleWidth / 2);

      if (this.curUpperArm == -1) this.curUpperArm = upperArm;
      if (this.curLowerArm == -1) this.curLowerArm = lowerArm;

      if (!(aChanger(this.curUpperArm, upperArm, (float) 0.05))) upperArm = this.curUpperArm;
      else this.curUpperArm = upperArm;
      if (!(aChanger(this.curLowerArm, lowerArm, (float) 0.05))) lowerArm = this.curLowerArm;
      else this.curLowerArm = lowerArm;

      Enumeration<ARSphericalView> e = getArViews().elements();

      if (getArViews().size() == 0) return;

      while (e.hasMoreElements()) {
        // If we have a location, and the view has one, update it's data
        try {
          ARSphericalView view = e.nextElement();
          // ------------
          if (view.isVisible()) {

            if (l != null && view.getLocation() != null) {
              float old_azi = view.getAzimuth();
              float old_incli = view.getInclination();
              float new_incli;
              if (aChanger(old_azi, l.bearingTo(view.getLocation()), (float) 0.05)) {
                view.setAzimuth((l.bearingTo(view.getLocation())) - 90);
              }
              if (view.getAzimuth() < 0) view.setAzimuth(360 + view.getAzimuth());
              if (l.hasAltitude() && view.getLocation().hasAltitude()) {
                new_incli =
                    (float)
                        Math.atan(
                            ((view.getLocation().getAltitude() - l.getAltitude())
                                / l.distanceTo(view.getLocation())));
                if (aChanger(old_incli, new_incli, (float) 0.05)) view.setInclination(new_incli);
              }
            }
          }

          //				if(!isVisibleX(leftArm, rightArm, view.azimuth))
          //				{
          //					view.visible = false;
          //					continue;
          //				}
          //				if(!isVisibleY(lowerArm, upperArm, view.inclination))
          //				{
          //					view.visible = false;
          //						continue;
          //				}
          //					view.setVisible(true);
          int tmp_x = (int) calcXvalue(leftArm, rightArm, view.getAzimuth());
          int tmp_y = (int) calcYvalue(lowerArm, upperArm, view.getInclination());

          if (view instanceof MagnitudePOI) {
            view.layout(
                (int) (((MagnitudePOI) view).getShiftX() + tmp_x),
                (int) (((MagnitudePOI) view).getShiftY() + tmp_y),
                (int)
                    ((((MagnitudePOI) view).getShiftX())
                        + tmp_x
                        + ((MagnitudePOI) view).getViewWidth()),
                (int)
                    (((MagnitudePOI) view).getShiftY()
                        + tmp_y
                        + ((MagnitudePOI) view).getViewHeight()));
          } else view.layout(tmp_x, tmp_y, tmp_x, tmp_y);
        } catch (Exception x) {
          Log.e("ArLayout", x.getMessage());
        }
      }
    }
    // 37.763557,-122.410719
  }