Search in sources :

Example 1 with ZonedUTMPoint

use of com.jwetherell.openmap.common.ZonedUTMPoint in project Osmand by osmandapp.

the class OsmAndFormatter method getFormattedCoordinates.

public static String getFormattedCoordinates(double lat, double lon, int outputFormat) {
    StringBuilder result = new StringBuilder();
    if (outputFormat == FORMAT_DEGREES_SHORT) {
        result.append(formatCoordinate(lat, outputFormat)).append(" ").append(formatCoordinate(lon, outputFormat));
    } else if (outputFormat == FORMAT_DEGREES || outputFormat == FORMAT_MINUTES || outputFormat == FORMAT_SECONDS) {
        boolean isLeftToRight = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_LTR;
        String rtlCoordinates = isLeftToRight ? "" : "\u200f";
        String rtlCoordinatesPunctuation = isLeftToRight ? ", " : " ,";
        result.append(rtlCoordinates).append(formatCoordinate(lat, outputFormat)).append(rtlCoordinates).append(" ").append(rtlCoordinates).append(lat > 0 ? NORTH : SOUTH).append(rtlCoordinates).append(rtlCoordinatesPunctuation).append(rtlCoordinates).append(formatCoordinate(lon, outputFormat)).append(rtlCoordinates).append(" ").append(rtlCoordinates).append(lon > 0 ? EAST : WEST);
    } else if (outputFormat == UTM_FORMAT) {
        ZonedUTMPoint pnt = new ZonedUTMPoint(new LatLonPoint(lat, lon));
        result.append(pnt.zone_number).append(pnt.zone_letter).append(" ").append((long) pnt.easting).append(" ").append((long) pnt.northing);
    } else if (outputFormat == OLC_FORMAT) {
        String r;
        try {
            r = getLocationOlcName(lat, lon);
        } catch (RuntimeException e) {
            r = "0, 0";
        }
        result.append(r);
    } else if (outputFormat == MGRS_FORMAT) {
        MGRSPoint pnt = new MGRSPoint(new LatLonPoint(lat, lon));
        try {
            result.append(pnt.toFlavoredString(5));
        } catch (java.lang.Error e) {
            e.printStackTrace();
        }
    } else if (outputFormat == SWISS_GRID_FORMAT) {
        double[] swissGrid = SwissGridApproximation.convertWGS84ToLV03(new LatLon(lat, lon));
        DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols(Locale.US);
        formatSymbols.setDecimalSeparator('.');
        formatSymbols.setGroupingSeparator(' ');
        DecimalFormat swissGridFormat = new DecimalFormat("###,###.##", formatSymbols);
        result.append(swissGridFormat.format(swissGrid[0]) + ", " + swissGridFormat.format(swissGrid[1]));
    } else if (outputFormat == SWISS_GRID_PLUS_FORMAT) {
        double[] swissGrid = SwissGridApproximation.convertWGS84ToLV95(new LatLon(lat, lon));
        DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols(Locale.US);
        formatSymbols.setDecimalSeparator('.');
        formatSymbols.setGroupingSeparator(' ');
        DecimalFormat swissGridFormat = new DecimalFormat("###,###.##", formatSymbols);
        result.append(swissGridFormat.format(swissGrid[0]) + ", " + swissGridFormat.format(swissGrid[1]));
    }
    return result.toString();
}
Also used : MGRSPoint(com.jwetherell.openmap.common.MGRSPoint) LatLon(net.osmand.data.LatLon) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) ZonedUTMPoint(com.jwetherell.openmap.common.ZonedUTMPoint) LatLonPoint(com.jwetherell.openmap.common.LatLonPoint)

Example 2 with ZonedUTMPoint

use of com.jwetherell.openmap.common.ZonedUTMPoint in project Osmand by osmandapp.

the class QuickSearchCoordinatesFragment method parseZonedUtmPoint.

private LatLon parseZonedUtmPoint(double northing, double easting, int zoneNumber, char zoneLetter) {
    try {
        ZonedUTMPoint point = new ZonedUTMPoint(northing, easting, zoneNumber, zoneLetter);
        LatLonPoint latLonPoint = point.ZonedUTMtoLL();
        return new LatLon(latLonPoint.getLatitude(), latLonPoint.getLongitude());
    } catch (NumberFormatException e) {
    }
    return null;
}
Also used : LatLon(net.osmand.data.LatLon) ZonedUTMPoint(com.jwetherell.openmap.common.ZonedUTMPoint) LatLonPoint(com.jwetherell.openmap.common.LatLonPoint)

Aggregations

LatLonPoint (com.jwetherell.openmap.common.LatLonPoint)2 ZonedUTMPoint (com.jwetherell.openmap.common.ZonedUTMPoint)2 LatLon (net.osmand.data.LatLon)2 MGRSPoint (com.jwetherell.openmap.common.MGRSPoint)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1