Android GeomagneticField - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android GeomagneticField class.

This code example shows how to use the following methods:getDeclination
	 *  
	 * @param location 
	 * @return Declination in degrees 
	 */ 
	public static float getDeclinationAt(float latitude, float longitude, float altitude) {
		GeomagneticField gf = new GeomagneticField(latitude, longitude, altitude, System.currentTimeMillis());
		return gf.getDeclination();
	} 
} 
6
CodeRank
This code example shows how to use the following methods:getDeclination
        // Just to satisfy the compiler 
        return "???"; 
    } 
 
    public static float getMagneticDeclination( Location location ) {
        GeomagneticField geoField = new GeomagneticField(
                (float)location.getLatitude(), (float)location.getLongitude(),
                (float)location.getAltitude(), System.currentTimeMillis() );
        // West declination is reported in negative values 
        return -1*geoField.getDeclination();
    } 
 
    public static double applyDeclination( double windDir, double magVar ) {
        return ( windDir+magVar+360 )%360;
    } 
 
    public static long applyDeclination( long heading, float declination ) {
        return Math.round( heading+declination+360 )%360;
    } 
 
5
CodeRank
This code example shows how to use the following methods:getDeclination
This code example shows how to use the following methods:getDeclination
		if (timestamp == 0) {
			// Hack for Samsung phones which don't populate the time field 
			timestamp = System.currentTimeMillis();
		} 
 
		GeomagneticField field = new GeomagneticField(
				(float) location.getLatitude(),
				(float) location.getLongitude(),
				(float) location.getAltitude(), timestamp);
		variation = field.getDeclination();
		 
//		Log.d("MyLocationService", "Variation reset to " + variation + " degrees."); 
	} 
 
	@Override 
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		// do nothing 
	} 
 
	@Override 
4
CodeRank
This code example shows how to use the following methods:getDeclination
    } 
    // Update magnetic declination once every minute 
    // -- diff between "true north" and magnetic north in degrees 
    if (declinationTime + 60000 < now) {
      declinationTime = now;
      GeomagneticField magneticField = new GeomagneticField(
          (float) location.getLatitude(), (float) location.getLongitude(),
          location.hasAltitude() ? (float) location.getAltitude() : 100f, // use 100m if not known
          declinationTime);
      compassDeclination = new Float(magneticField.getDeclination());
    } 
    // If there is no bearing (lack of motion or network location), use latest compass heading 
    if (!location.hasBearing() || !location.hasSpeed() || location.getSpeed() < 0.3f) {
      location.setBearing(compassHeading);
    } 
 
    // Update current location 
    if (currentLocation != null) {
      currentLocation.set(location);
    } else { 
4
CodeRank
This code example shows how to use the following methods:getDeclination
        if (timestamp == 0) {
          // Hack for Samsung phones which don't populate the time field 
          timestamp = System.currentTimeMillis();
        } 
 
        GeomagneticField field = new GeomagneticField(
            (float) location.getLatitude(),
            (float) location.getLongitude(),
            (float) location.getAltitude(),
            timestamp);
        variation = field.getDeclination();
      } 
 
     
    public void onLocationChanged(Location location) {
		super.onLocationChanged(location);
/* 
        GeoPoint point = new GeoPoint( 
                (int) ((double) location.getLatitude() * E6), 
                (int) ((double) location.getLongitude() * E6)); 
4
CodeRank
This code example shows how to use the following methods:getDeclination
        if (timestamp == 0) {
          // Hack for Samsung phones which don't populate the time field 
          timestamp = System.currentTimeMillis();
        } 
 
        GeomagneticField field = new GeomagneticField(
            (float) location.getLatitude(),
            (float) location.getLongitude(),
            (float) location.getAltitude(),
            timestamp);
        variation = field.getDeclination();
      } 
 
     
    public void onLocationChanged(Location location) {
		super.onLocationChanged(location);
/* 
        GeoPoint point = new GeoPoint( 
                (int) ((double) location.getLatitude() * E6), 
                (int) ((double) location.getLongitude() * E6)); 
4
CodeRank
This code example shows how to use the following methods:getDeclination
        if (timestamp == 0) {
          // Hack for Samsung phones which don't populate the time field 
          timestamp = System.currentTimeMillis();
        } 
 
        GeomagneticField field = new GeomagneticField(
            (float) location.getLatitude(),
            (float) location.getLongitude(),
            (float) location.getAltitude(),
            timestamp);
        variation = field.getDeclination();
      } 
 
     
    public void onLocationChanged(Location location) {
		super.onLocationChanged(location);
/* 
        GeoPoint point = new GeoPoint( 
                (int) ((double) location.getLatitude() * E6), 
                (int) ((double) location.getLongitude() * E6)); 
4
CodeRank
This code example shows how to use the following methods:getDeclination
        if (timestamp == 0) {
          // Hack for Samsung phones which don't populate the time field 
          timestamp = System.currentTimeMillis();
        } 
 
        GeomagneticField field = new GeomagneticField(
            (float) location.getLatitude(),
            (float) location.getLongitude(),
            (float) location.getAltitude(),
            timestamp);
        variation = field.getDeclination();
      } 
 
     
    public void onLocationChanged(Location location) {
		super.onLocationChanged(location);
/* 
        GeoPoint point = new GeoPoint( 
                (int) ((double) location.getLatitude() * E6), 
                (int) ((double) location.getLongitude() * E6)); 
4
CodeRank
This code example shows how to use the following methods:getDeclination
        if (timestamp == 0) {
          // Hack for Samsung phones which don't populate the time field 
          timestamp = System.currentTimeMillis();
        } 
 
        GeomagneticField field = new GeomagneticField(
            (float) location.getLatitude(),
            (float) location.getLongitude(),
            (float) location.getAltitude(),
            timestamp);
        variation = field.getDeclination();
      } 
 
     
    public void onLocationChanged(Location location) {
		super.onLocationChanged(location);
/* 
        GeoPoint point = new GeoPoint( 
                (int) ((double) location.getLatitude() * E6), 
                (int) ((double) location.getLongitude() * E6)); 
4
CodeRank
This code example shows how to use the following methods:getDeclination
        if (timestamp == 0) {
            // Hack for Samsung phones which don't populate the time field 
            timestamp = System.currentTimeMillis();
        } 
 
        GeomagneticField field = new GeomagneticField((float) location
                .getLatitude(), (float) location.getLongitude(),
                (float) location.getAltitude(), timestamp);
        variation = field.getDeclination();
    } 
 
    public void onLocationChanged(Location location) {
        super.onLocationChanged(location);
        /* 
         * GeoPoint point = new GeoPoint( (int) ((double) location.getLatitude() 
         * * E6), (int) ((double) location.getLongitude() * E6)); 
         *  
         * mv.getController().animateTo(point); setVariation(location); 
         */ 
    } 
4
CodeRank
This code example shows how to use the following methods:getDeclination
        if (timestamp == 0) {
            // Hack for Samsung phones which don't populate the time field 
            timestamp = System.currentTimeMillis();
        } 
 
        GeomagneticField field = new GeomagneticField((float) location
                .getLatitude(), (float) location.getLongitude(),
                (float) location.getAltitude(), timestamp);
        variation = field.getDeclination();
    } 
 
    public void onLocationChanged(Location location) {
        super.onLocationChanged(location);
        /* 
         * GeoPoint point = new GeoPoint( (int) ((double) location.getLatitude() 
         * * E6), (int) ((double) location.getLongitude() * E6)); 
         *  
         * mv.getController().animateTo(point); setVariation(location); 
         */ 
    } 
4
CodeRank
This code example shows how to use the following methods:getDeclination
			} 
		} 
	} 
	 
	public static float calculateTrueNorth(float degrees, float lat, float lon, float alt, long milli){
		GeomagneticField geoField = new GeomagneticField(lat, lon, alt, milli);
		 
		float ret = degrees + geoField.getDeclination();
		if(ret < 0.0f)
			ret += 360.0f;
		 
		return ret;
	} 
	 
	public static float getOffset(double lat1, double lat2, double lon1, double lon2, float bearing){
		GeomagneticField geoMag = new GeomagneticField((float)lat1, (float)lon1, 0, new Date().getTime());
		bearing += geoMag.getDeclination();
		 
	    lat1 = Math.toRadians(lat1);
	    lat2 = Math.toRadians(lat2);
4
CodeRank
This code example shows how to use the following methods:getDeclination
        if (timestamp == 0) {
            // Hack for Samsung phones which don't populate the time field 
            timestamp = System.currentTimeMillis();
        } 
 
        GeomagneticField field = new GeomagneticField(
                (float) location.getLatitude(),
                (float) location.getLongitude(),
                (float) location.getAltitude(), timestamp);
        variation = field.getDeclination();
    } 
 
    public void onLocationChanged(Location location) {
        super.onLocationChanged(location);
 
//        if (toggle.isChecked() == true) { 
//            GeoPoint center = mv.getMapCenter(); 
//            int top = center.getLatitudeE6() - mv.getLatitudeSpan() / 2; // 画面上に見える範囲 
//            int bottom = center.getLatitudeE6() + mv.getLatitudeSpan() / 2; 
//            int left = center.getLongitudeE6() - mv.getLongitudeSpan() / 2; 
4
CodeRank
This code example shows how to use the following methods:getDeclination
	} 
 
	@Override 
	public void onLocationChanged(Location loc) {
		//calculate and store declination for compass offsetting to true north 
        GeomagneticField gmf = new GeomagneticField(
            (float)loc.getLatitude(), (float)loc.getLongitude(), (float)loc.getAltitude(), System.currentTimeMillis());
        this.declination = gmf.getDeclination();
	} 
 
	@Override 
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub 
		 
	} 
 
	@Override 
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub 
		 
5
CodeRank
This code example shows how to use the following methods:getDeclination
		 * travel such great distances in reality mode. 
		 */ 
		if (!mHasDeclination) {
			float altimeter = 0;
 
			GeomagneticField field = new GeomagneticField(
					(float) location.getLatitude(),
					(float) location.getLongitude(), altimeter,
					System.currentTimeMillis());
 
			mDeclination = field.getDeclination();
 
			mHasDeclination = true;
		} 
	} 
 
	public void onProviderDisabled(String provider) {
 
	} 
 
5
CodeRank
This code example shows how to use the following methods:getDeclination
        if (timestamp == 0) {
            // Hack for Samsung phones which don't populate the time field 
            timestamp = System.currentTimeMillis();
        } 
 
        GeomagneticField field = new GeomagneticField(
            (float) location.getLatitude(),
            (float) location.getLongitude(),
            (float) location.getAltitude(),
            timestamp);
        variation = field.getDeclination();
      } 
 
     
    public void onLocationChanged(Location location) {
        super.onLocationChanged(location);
         
        GeoPoint point = new GeoPoint(
                (int) ((double) location.getLatitude() * E6),
                (int) ((double) location.getLongitude() * E6));
5
CodeRank
This code example shows how to use the following methods:getDeclination
	synchronized public boolean hasLocation() { 
		return currentLocation != null;
	} 
	 
	private float getDeclination() { 
		GeomagneticField field = new GeomagneticField(
				(float) currentLocation.getLatitude(),
				(float) currentLocation.getLongitude(),
				(float) currentLocation.getAltitude(),
				currentLocation.getTime());
		return field.getDeclination();
	} 
	 
	/** 
	 * Information about the difference between the current location and the target location 
	 * including accuracy information about the current location. 
	 *  
	 * @author tgnourse 
	 */ 
	public class Difference { 
5
CodeRank
This code example shows how to use the following methods:getDeclination
	@Override 
	public void onLocationChanged(final Location location) {
		Log.i("RadarActivity", location.toString());
		mLastLocationMillis = SystemClock.elapsedRealtime();
		mLastLocation = location;
		GeomagneticField geoField = new GeomagneticField(Double.valueOf(location.getLatitude()).floatValue(), Double.valueOf(location.getLongitude()).floatValue(), Double.valueOf(location.getAltitude()).floatValue(), System.currentTimeMillis());
		mRadarView.setDeclination(geoField.getDeclination());
		mMapCenter = location;
		calculateDestinationAndBearing(); 
	} 
 
	@Override 
	public void onStatusChanged(String provider, int status, Bundle extras) {
 
	} 
 
	private int getGPSColor(final int numSatellites) {
		final float frac = 255 / 6f;
		final int a = 0xff;
		final int b = 0x00;
5
CodeRank
This code example shows how to use the following methods:getDeclination
	synchronized public boolean hasLocation() { 
		return currentLocation != null;
	} 
	 
	private float getDeclination() { 
		GeomagneticField field = new GeomagneticField(
				(float) currentLocation.getLatitude(),
				(float) currentLocation.getLongitude(),
				(float) currentLocation.getAltitude(),
				currentLocation.getTime());
		return field.getDeclination();
	} 
	 
	/** 
	 * Information about the difference between the current location and the target location 
	 * including accuracy information about the current location. 
	 *  
	 * @author tgnourse 
	 */ 
	public class Difference { 
5
CodeRank
This code example shows how to use the following methods:getDeclination
This code example shows how to use the following methods:getDeclination
	public long getAge() { 
		return System.currentTimeMillis() - lastTime;
	} 
	 
	public float getDeclination() { 
		GeomagneticField field = new GeomagneticField(
				(float) currentLocation.getLatitude(),
				(float) currentLocation.getLongitude(),
				(float) currentLocation.getAltitude(),
				currentLocation.getTime());
		return field.getDeclination();
	} 
	 
	synchronized public Difference getDifference(TargetLocation target) {
		double adjacent = currentLocation.distanceTo(target) * Util.FEET_INA_METER;
		double opposite = target.getAltitude() * Util.FEET_INA_METER;
		double hypotenuse = Math.sqrt(opposite*opposite + adjacent*adjacent);
		float azimuth = (currentLocation.bearingTo(target) + 360) % 360;
		double altitude = Math.atan(opposite / adjacent) * 57.2957795;
		float speed = target.getSpeed() * Util.MPH_INA_MPS; 
5
CodeRank
This code example shows how to use the following methods:
	        double alt = loc.getAltitude();
	        SessionStorage.set_lat(lat);
	        SessionStorage.set_lng(lng);
	         
	        //calculate and store the Magnetic Declination for the current location 
	        geoField = new GeomagneticField((float) (lat), (float) (lng), (float) (alt), System.currentTimeMillis());
	        SessionStorage.set_dec((float) Math.toRadians(geoField.getDeclination()));
	         
            // Run next activity 
	        Intent intent = new Intent();
            intent.setClass(sPlashScreen, GridViewMenu.class);
            startActivity(intent);
             
            //Turn off the GPS 
            locationManager.removeUpdates(locationListener);
             
            //Remove Splash Screen from Memory 
            finish();
	     }   
	   
4
CodeRank
This code example shows how to use the following methods:getDeclination
		Location curLoc = mixContext.getCurrentLocation();
		if (null == curLoc) {
			return; 
		} 
		 
		GeomagneticField gmf = new GeomagneticField((float)curLoc.getLatitude(),
				(float)curLoc.getLongitude(),
				(float)curLoc.getAltitude(),
				System.currentTimeMillis());
 
		double angleY = Math.toRadians(-gmf.getDeclination());
		m4.set((float) Math.cos(angleY), 0f,
				(float) Math.sin(angleY), 0f, 1f, 0f, (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY));
 
		mixContext.declination = gmf.getDeclination();
	} 
	 
	 
	@Override 
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
4
CodeRank
This code example shows how to use the following methods:
     */ 
    @Override 
    public void onLocationChanged(Location location) {
    	if (location==null) throw new NullPointerException();
        currentLocation=(location);
        gmf = new GeomagneticField((float) currentLocation.getLatitude(), 
                                   (float) currentLocation.getLongitude(),
                                   (float) currentLocation.getAltitude(), 
                                   System.currentTimeMillis());
    } 
     
    /** 
     * {@inheritDoc} 
     */ 
	@Override 
	public void onProviderDisabled(String provider) {
		//Ignore 
	} 
     
    /** 
4
CodeRank
This code example shows how to use the following methods:getDeclination
		//Log.d(TAG, "getAzimuth " + accMagOrientation[0]); 
		float azimuth = (float)Math.toDegrees(accMagOrientation[0]);
		azimuth = (azimuth +360) % 360;
		//Log.d(TAG, "getAzimuth " + azimuth); 
		if (geoField != null) {
			azimuth += geoField.getDeclination();
		} 
		//Log.d(TAG, "getAzimuth " + azimuth); 
		return azimuth;
	} 
 
	protected Integer getBearing() {
		if ( rocketLocation == null || myLocation == null ) {
			return null; 
		} 
		float rocketBearing = normalizeDegree(myLocation.bearingTo(getRocketLocation()));
		return Math.round(rocketBearing);
	} 
 
	private float normalizeDegree(float value){
3
CodeRank
This code example shows how to use the following methods:getDeclination
 
        //Convert from radians to degrees 
        floatBearing = Math.toDegrees(floatBearing); //degrees east of true north (180 to -180)
         
        //Compensate for the difference between true north and magnetic north 
        if (gmf!=null) floatBearing += gmf.getDeclination();
         
        //adjust to 0-360 
        if (floatBearing<0) floatBearing+=360;
         
 
        computing.set(false);
 
        builder.setLength(0);
        builder.append("X " + rotation[0] + "\nY " + rotation[1] + "\nZ " + rotation[2]+"\n");
builder.append("X " + rotation[3] + "\nY " + rotation[4] + "\nZ " + rotation[5]+"\n");
builder.append("X " + rotation[6] + "\nY " + rotation[7] + "\nZ " + rotation[8]+"\n");
        textView.setText(builder.toString());
 
    } 
3
CodeRank
This code example shows how to use the following methods:
This code example shows how to use the following methods:getDeclination
    } 
     
    public static int determineMagDec(double lat, double lng){
    	Time time = new Time();
    	time.setToNow();
    	GeomagneticField geomag = new GeomagneticField((float)lat, (float)lng, (float)0, time.toMillis(false));
    	 
    	return (int)geomag.getDeclination();
    } 
     
    public static String determineCity(Geocoder myLocation, double lat, double lng) {
     
    	List<Address> myList = null ;
    	String city = "Unknown";
    	 
    	try { 
			myList = myLocation.getFromLocation(lat, lng, 1);
    	}  
    	catch (Exception e) {
    		return city ;
4
CodeRank
This code example shows how to use the following methods:
  public void onLocationChanged(Location location) {
    float latitude = new Double(location.getLatitude()).floatValue();
    float longitude = new Double(location.getLongitude()).floatValue();
    float altitude = new Double(location.getAltitude()).floatValue();
    geomagnetic = new GeomagneticField(
        latitude, longitude, altitude, new Date().getTime());
  } 
 
  public void onProviderDisabled(String provider) {
  } 
 
  public void onProviderEnabled(String provider) {
  } 
 
  public void onStatusChanged(String provider, int status, Bundle extras) {
  } 
 
  public void onAccuracyChanged(Sensor sensor, int accuracy) {
  } 
 
4
CodeRank

Related Android GeomagneticField Questions & Answers:

See Code Examples for Android GeomagneticField Methods: