Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onSensorChanged(SensorEvent event) {
- float azimuth = event.values[0];
- Location currentLoc = getHelper().getCurrentLocation();
- if(currentLoc == null || cardinal == null || cardinal.getLocation() == null) {
- return;
- }
- azimuth = (float) Math.toDegrees(azimuth);
- GeomagneticField geoField = new GeomagneticField(
- (float) currentLoc.getLatitude(),
- (float) currentLoc.getLongitude(),
- (float) currentLoc.getAltitude(),
- System.currentTimeMillis());
- azimuth += geoField.getDeclination(); // converts magnetic north into true north
- float bearing = currentLoc.bearingTo(cardinal.getLocation()); // (it's already in degrees)
- float direction = azimuth - bearing;
- direction = -direction;
- if(compass != null) {
- compass.setDirection(direction);
- }
- }
- public void onDraw(Canvas canvas) { //
- int height = this.getHeight(); //
- int width = this.getWidth();
- canvas.rotate(direction, width / 2, height / 2); //
- super.onDraw(canvas); //
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement