Java Decimal Format prettyPrintLatLon(double coord, boolean isCoordKindLat)

Here you can find the source of prettyPrintLatLon(double coord, boolean isCoordKindLat)

Description

pretty Print Lat Lon

License

Open Source License

Declaration

public static String prettyPrintLatLon(double coord, boolean isCoordKindLat) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) OSMCB developers/*from   ww  w. ja  v a 2  s.c  o  m*/
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

import java.text.DecimalFormat;

public class Main {
    private static final DecimalFormat cDmsMinuteFormatter = new DecimalFormat("00");
    private static final DecimalFormat cDmsSecondFormatter = new DecimalFormat("00.0");

    public static String prettyPrintLatLon(double coord, boolean isCoordKindLat) {
        boolean neg = coord < 0.0;
        String c;
        if (isCoordKindLat) {
            c = (neg ? "S" : "N");
        } else {
            c = (neg ? "W" : "E");
        }
        double tAbsCoord = Math.abs(coord);
        int tDegree = (int) tAbsCoord;
        double tTmpMinutes = (tAbsCoord - tDegree) * 60;
        int tMinutes = (int) tTmpMinutes;
        double tSeconds = (tTmpMinutes - tMinutes) * 60;
        return c + tDegree + "\u00B0" + cDmsMinuteFormatter.format(tMinutes) + "\'"
                + cDmsSecondFormatter.format(tSeconds) + "\"";
    }
}

Related

  1. listToString(List list)
  2. numToString(double num)
  3. pad(double n)
  4. padding(final double number)
  5. padToMinWidth(double num, int minWidth)
  6. print(double[] y)
  7. printAlpha(double a[])
  8. printAngle(double angle)
  9. printArray(String title, double[] vect)