Example usage for android.location Location FORMAT_MINUTES

List of usage examples for android.location Location FORMAT_MINUTES

Introduction

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

Prototype

int FORMAT_MINUTES

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

Click Source Link

Document

Constant used to specify formatting of a latitude or longitude in the form "[+-]DDD:MM.MMMMM" where D indicates degrees and M indicates minutes of arc (1 minute = 1/60th 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);//from   w  ww  . 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

/**
 * Formats coordinate value to string based on output type (modified version
 * from Android API)/*from   w  ww  . ja  va 2s. com*/
 */
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();
}