Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. public void onSensorChanged(SensorEvent event) {
  2. float azimuth = event.values[0];
  3. Location currentLoc = getHelper().getCurrentLocation();
  4. if(currentLoc == null || cardinal == null || cardinal.getLocation() == null) {
  5. return;
  6. }
  7.  
  8. azimuth = (float) Math.toDegrees(azimuth);
  9. GeomagneticField geoField = new GeomagneticField(
  10. (float) currentLoc.getLatitude(),
  11. (float) currentLoc.getLongitude(),
  12. (float) currentLoc.getAltitude(),
  13. System.currentTimeMillis());
  14.  
  15. azimuth += geoField.getDeclination(); // converts magnetic north into true north
  16. float bearing = currentLoc.bearingTo(cardinal.getLocation()); // (it's already in degrees)
  17. float direction = azimuth - bearing;
  18. direction = -direction;
  19. if(compass != null) {
  20. compass.setDirection(direction);
  21. }
  22. }
  23.  
  24. public void onDraw(Canvas canvas) { //
  25. int height = this.getHeight(); //
  26. int width = this.getWidth();
  27.  
  28. canvas.rotate(direction, width / 2, height / 2); //
  29. super.onDraw(canvas); //
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement