use of com.jwetherell.openmap.common.LatLonPoint in project Osmand by osmandapp.
the class QuickSearchCoordinatesFragment method applyFormat.
private boolean applyFormat(int format, boolean forceApply) {
if (currentFormat != format || forceApply) {
int prevFormat = currentFormat;
currentFormat = format;
formatEdit.setText(PointDescription.formatToHumanString(getMyApplication(), currentFormat));
final EditText latEdit = ((EditText) view.findViewById(R.id.latitudeEditText));
final EditText lonEdit = ((EditText) view.findViewById(R.id.longitudeEditText));
setInputTypeDependingOnFormat(new EditText[] { latEdit, lonEdit });
updateControlsVisibility();
if (currentFormat == PointDescription.UTM_FORMAT) {
final EditText northingEdit = ((EditText) view.findViewById(R.id.northingEditText));
final EditText eastingEdit = ((EditText) view.findViewById(R.id.eastingEditText));
final EditText zoneEdit = ((EditText) view.findViewById(R.id.zoneEditText));
if (currentLatLon != null) {
UTMPoint pnt = new UTMPoint(new LatLonPoint(currentLatLon.getLatitude(), currentLatLon.getLongitude()));
zoneEdit.setText(pnt.zone_number + "" + pnt.zone_letter);
northingEdit.setText(((long) pnt.northing) + "");
eastingEdit.setText(((long) pnt.easting) + "");
} else if (prevFormat == PointDescription.OLC_FORMAT) {
zoneEdit.setText(olcEdit.getText());
northingEdit.setText("");
eastingEdit.setText("");
} else {
zoneEdit.setText(latEdit.getText());
northingEdit.setText("");
eastingEdit.setText("");
}
} else if (currentFormat == PointDescription.OLC_FORMAT) {
if (currentLatLon != null) {
String olc = OpenLocationCode.encode(currentLatLon.getLatitude(), currentLatLon.getLongitude());
olcEdit.setText(olc);
olcInfo.setText(provideOlcInfo(olc));
} else if (prevFormat == PointDescription.UTM_FORMAT) {
olcEdit.setText(zoneEdit.getText());
olcInfo.setText(provideOlcInfo(olcEdit.getText().toString()));
} else {
olcEdit.setText(latEdit.getText());
olcInfo.setText(provideOlcInfo(olcEdit.getText().toString()));
}
} else {
if (currentLatLon != null) {
latEdit.setText(LocationConvert.convert(MapUtils.checkLatitude(currentLatLon.getLatitude()), currentFormat));
lonEdit.setText(LocationConvert.convert(MapUtils.checkLongitude(currentLatLon.getLongitude()), currentFormat));
} else if (prevFormat == PointDescription.UTM_FORMAT) {
latEdit.setText(zoneEdit.getText());
lonEdit.setText("");
} else if (prevFormat == PointDescription.OLC_FORMAT) {
latEdit.setText(olcEdit.getText());
lonEdit.setText("");
}
}
return currentLatLon != null;
} else {
return false;
}
}
use of com.jwetherell.openmap.common.LatLonPoint in project Osmand by osmandapp.
the class QuickSearchCoordinatesFragment method parseLocation.
private void parseLocation() {
LatLon loc;
try {
if (currentFormat == LocationConvert.UTM_FORMAT) {
double northing = Double.parseDouble(northingEdit.getText().toString());
double easting = Double.parseDouble(eastingEdit.getText().toString());
String zone = zoneEdit.getText().toString();
char c = zone.charAt(zone.length() - 1);
int z = Integer.parseInt(zone.substring(0, zone.length() - 1));
UTMPoint upoint = new UTMPoint(northing, easting, z, c);
LatLonPoint ll = upoint.toLatLonPoint();
loc = new LatLon(ll.getLatitude(), ll.getLongitude());
} else if (currentFormat == LocationConvert.OLC_FORMAT) {
String olcText = olcEdit.getText().toString();
olcInfo.setText(provideOlcInfo(olcText));
// can throw exception for invalid OLC string
OpenLocationCode.CodeArea codeArea = OpenLocationCode.decode(olcText);
loc = new LatLon(codeArea.getCenterLatitude(), codeArea.getCenterLongitude());
} else {
double lat = LocationConvert.convert(latEdit.getText().toString(), true);
double lon = LocationConvert.convert(lonEdit.getText().toString(), true);
loc = new LatLon(lat, lon);
}
currentLatLon = loc;
} catch (Exception e) {
currentLatLon = null;
}
updateLocationCell(currentLatLon);
}
use of com.jwetherell.openmap.common.LatLonPoint in project Osmand by osmandapp.
the class NavigatePointFragment method showCurrentFormat.
protected void showCurrentFormat(LatLon l) {
final EditText latEdit = ((EditText) view.findViewById(R.id.LatitudeEdit));
final EditText lonEdit = ((EditText) view.findViewById(R.id.LongitudeEdit));
boolean utm = currentFormat == PointDescription.UTM_FORMAT;
view.findViewById(R.id.easting_row).setVisibility(utm ? View.VISIBLE : View.GONE);
view.findViewById(R.id.northing_row).setVisibility(utm ? View.VISIBLE : View.GONE);
view.findViewById(R.id.zone_row).setVisibility(utm ? View.VISIBLE : View.GONE);
view.findViewById(R.id.lat_row).setVisibility(!utm ? View.VISIBLE : View.GONE);
view.findViewById(R.id.lon_row).setVisibility(!utm ? View.VISIBLE : View.GONE);
if (currentFormat == PointDescription.UTM_FORMAT) {
final EditText northingEdit = ((EditText) view.findViewById(R.id.NorthingEdit));
final EditText eastingEdit = ((EditText) view.findViewById(R.id.EastingEdit));
final EditText zoneEdit = ((EditText) view.findViewById(R.id.ZoneEdit));
UTMPoint pnt = new UTMPoint(new LatLonPoint(l.getLatitude(), l.getLongitude()));
zoneEdit.setText(pnt.zone_number + "" + pnt.zone_letter);
northingEdit.setText(((long) pnt.northing) + "");
eastingEdit.setText(((long) pnt.easting) + "");
} else {
latEdit.setText(LocationConvert.convert(MapUtils.checkLatitude(l.getLatitude()), currentFormat));
lonEdit.setText(LocationConvert.convert(MapUtils.checkLongitude(l.getLongitude()), currentFormat));
}
}
use of com.jwetherell.openmap.common.LatLonPoint in project Osmand by osmandapp.
the class NavigatePointFragment method parseLocation.
protected LatLon parseLocation() {
LatLon loc;
if (currentFormat == LocationConvert.UTM_FORMAT) {
double northing = Double.parseDouble(((EditText) view.findViewById(R.id.NorthingEdit)).getText().toString());
double easting = Double.parseDouble(((EditText) view.findViewById(R.id.EastingEdit)).getText().toString());
String zone = ((EditText) view.findViewById(R.id.ZoneEdit)).getText().toString();
char c = zone.charAt(zone.length() - 1);
int z = Integer.parseInt(zone.substring(0, zone.length() - 1));
UTMPoint upoint = new UTMPoint(northing, easting, z, c);
LatLonPoint ll = upoint.toLatLonPoint();
loc = new LatLon(ll.getLatitude(), ll.getLongitude());
} else {
double lat = LocationConvert.convert(((EditText) view.findViewById(R.id.LatitudeEdit)).getText().toString(), true);
double lon = LocationConvert.convert(((EditText) view.findViewById(R.id.LongitudeEdit)).getText().toString(), true);
loc = new LatLon(lat, lon);
}
return loc;
}
use of com.jwetherell.openmap.common.LatLonPoint in project Osmand by osmandapp.
the class PointDescription method getLocationNamePlain.
public static String getLocationNamePlain(Context ctx, double lat, double lon) {
OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
int f = st.COORDINATES_FORMAT.get();
if (f == PointDescription.UTM_FORMAT) {
UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " " + ((long) pnt.northing);
} else if (f == PointDescription.OLC_FORMAT) {
try {
return getLocationOlcName(lat, lon);
} catch (RuntimeException e) {
e.printStackTrace();
return "0, 0";
}
} else {
try {
return LocationConvert.convert(lat, f) + ", " + LocationConvert.convert(lon, f);
} catch (RuntimeException e) {
e.printStackTrace();
return "0, 0";
}
}
}
Aggregations