Example usage for android.location Location FORMAT_SECONDS

List of usage examples for android.location Location FORMAT_SECONDS

Introduction

In this page you can find the example usage for android.location Location FORMAT_SECONDS.

Prototype

int FORMAT_SECONDS

To view the source code for android.location Location FORMAT_SECONDS.

Click Source Link

Document

Constant used to specify formatting of a latitude or longitude in the form "DDD:MM:SS.SSSSS" where D indicates degrees, M indicates minutes of arc, and S indicates seconds of arc (1 minute = 1/60th of a degree, 1 second = 1/3600th of a degree).

Usage

From source file:Main.java

public static String formatCoordinate(double coordinate, int outputType) {
    StringBuilder sb = new StringBuilder();
    char endChar = DEGREE_CHAR;

    DecimalFormat df = new DecimalFormat("###.####");
    if (outputType == Location.FORMAT_MINUTES || outputType == Location.FORMAT_SECONDS) {

        df = new DecimalFormat("##.###");

        int degrees = (int) Math.floor(coordinate);
        sb.append(degrees);//ww  w.  j a  va  2 s .c o  m
        sb.append(DEGREE_CHAR); // degrees sign
        endChar = '\''; // minutes sign
        coordinate -= degrees;
        coordinate *= 60.0;

        if (outputType == Location.FORMAT_SECONDS) {

            df = new DecimalFormat("##.##");

            int minutes = (int) Math.floor(coordinate);
            sb.append(minutes);
            sb.append('\''); // minutes sign
            endChar = '\"'; // seconds sign
            coordinate -= minutes;
            coordinate *= 60.0;
        }
    }

    sb.append(df.format(coordinate));
    sb.append(endChar);

    return sb.toString();
}

From source file:com.nextgis.firereporter.ScanexNotificationItem.java

protected void Prepare(Context c) {
    this.nID = -1;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    nFormat = prefs.getInt(SettingsActivity.KEY_PREF_COORD_FORMAT + "_int", Location.FORMAT_SECONDS);
    sCoordLat = (String) c.getResources().getText(R.string.coord_lat);
    sCoordLon = (String) c.getResources().getText(R.string.coord_lon);

    sN = (String) c.getResources().getText(R.string.compas_N);
    sS = (String) c.getResources().getText(R.string.compas_S);
    sW = (String) c.getResources().getText(R.string.compas_W);
    sE = (String) c.getResources().getText(R.string.compas_E);
}

From source file:com.nextgis.firereporter.ScanexNotificationItem.java

/**
 * Formats coordinate value to string based on output type (modified version
 * from Android API)//w  w w  .ja  v  a 2 s. co  m
 */
public static String formatCoord(double coordinate, int outputType) {

    StringBuilder sb = new StringBuilder();
    char endChar = DEGREE_CHAR;

    DecimalFormat df = new DecimalFormat("###.######");
    if (outputType == Location.FORMAT_MINUTES || outputType == Location.FORMAT_SECONDS) {

        df = new DecimalFormat("##.###");

        int degrees = (int) Math.floor(coordinate);
        sb.append(degrees);
        sb.append(DEGREE_CHAR); // degrees sign
        endChar = '\''; // minutes sign
        coordinate -= degrees;
        coordinate *= 60.0;

        if (outputType == Location.FORMAT_SECONDS) {

            df = new DecimalFormat("##.##");

            int minutes = (int) Math.floor(coordinate);
            sb.append(minutes);
            sb.append('\''); // minutes sign
            endChar = '\"'; // seconds sign
            coordinate -= minutes;
            coordinate *= 60.0;
        }
    }

    sb.append(df.format(coordinate));
    sb.append(endChar);

    return sb.toString();
}

From source file:com.tritop.androsense2.fragments.GpsFragment.java

@Override
public void onLocationChanged(Location loc) {
    mLatitude = loc.getLatitude();/*  w ww.  java2 s  .  c om*/
    mAltitude = loc.getAltitude();
    mLongitude = loc.getLongitude();
    mAccuracy = loc.getAccuracy();
    mLatitudeView.setText(SensorInfo.formatGpsPosition(Location.convert(mLatitude, Location.FORMAT_SECONDS)));
    mLongitudeView.setText(SensorInfo.formatGpsPosition(Location.convert(mLongitude, Location.FORMAT_SECONDS)));
    mAltitudeView.setText(String.format("%.0f", mAltitude) + " m");
}

From source file:com.nextgis.uikobserver.MainActivity.java

public String GetCoordinates() {
    String sOut;/*from  ww w .  j a  v  a 2s.  c om*/
    sOut = sCoordLat + ": " + formatLat(dfLat, Location.FORMAT_SECONDS);
    sOut += "\n";
    sOut += sCoordLon + ": " + formatLon(dfLon, Location.FORMAT_SECONDS);

    return sOut;
}