Support OLC in point description

This commit is contained in:
theirix 2017-01-08 17:18:15 +03:00
parent 6a730e7cf1
commit 5a3d6939f5

View file

@ -9,6 +9,7 @@ import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.google.openlocationcode.OpenLocationCode;
import com.jwetherell.openmap.common.LatLonPoint; import com.jwetherell.openmap.common.LatLonPoint;
import com.jwetherell.openmap.common.UTMPoint; import com.jwetherell.openmap.common.UTMPoint;
@ -156,6 +157,8 @@ public class PointDescription {
UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon)); UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " " return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " "
+ ((long) pnt.northing); + ((long) pnt.northing);
} else if (f == PointDescription.OLC_FORMAT) {
return getLocationOlcName(lat, lon);
} else { } else {
try { try {
return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, LocationConvert.convert(lat, f), return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, LocationConvert.convert(lat, f),
@ -174,6 +177,8 @@ public class PointDescription {
UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon)); UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " " return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " "
+ ((long) pnt.northing); + ((long) pnt.northing);
} else if (f == PointDescription.OLC_FORMAT) {
return getLocationOlcName(lat, lon);
} else { } else {
try { try {
return LocationConvert.convert(lat, f) + ", " + LocationConvert.convert(lon, f); return LocationConvert.convert(lat, f) + ", " + LocationConvert.convert(lon, f);
@ -184,6 +189,10 @@ public class PointDescription {
} }
} }
public static String getLocationOlcName(double lat, double lon) {
return OpenLocationCode.encode(lat, lon);
}
public boolean contextMenuDisabled() { public boolean contextMenuDisabled() {
return POINT_TYPE_WORLD_REGION_SHOW_ON_MAP.equals(type); return POINT_TYPE_WORLD_REGION_SHOW_ON_MAP.equals(type);
} }
@ -338,6 +347,7 @@ public class PointDescription {
public static final int FORMAT_MINUTES = LocationConvert.FORMAT_MINUTES; public static final int FORMAT_MINUTES = LocationConvert.FORMAT_MINUTES;
public static final int FORMAT_SECONDS = LocationConvert.FORMAT_SECONDS; public static final int FORMAT_SECONDS = LocationConvert.FORMAT_SECONDS;
public static final int UTM_FORMAT = LocationConvert.UTM_FORMAT; public static final int UTM_FORMAT = LocationConvert.UTM_FORMAT;
public static final int OLC_FORMAT = LocationConvert.OLC_FORMAT;
public static String formatToHumanString(Context ctx, int format) { public static String formatToHumanString(Context ctx, int format) {
switch (format) { switch (format) {
@ -349,6 +359,8 @@ public class PointDescription {
return ctx.getString(R.string.navigate_point_format_DMS); return ctx.getString(R.string.navigate_point_format_DMS);
case LocationConvert.UTM_FORMAT: case LocationConvert.UTM_FORMAT:
return "UTM"; return "UTM";
case LocationConvert.OLC_FORMAT:
return "OLC";
default: default:
return "Unknown format"; return "Unknown format";
} }