add method to compose list with coordinates and url

This commit is contained in:
madwasp79 2019-06-20 12:58:10 +03:00
parent 4d9cf94f99
commit bb4528bf6a
3 changed files with 49 additions and 0 deletions

View file

@ -8,10 +8,13 @@ import com.google.openlocationcode.OpenLocationCode;
import com.jwetherell.openmap.common.LatLonPoint;
import com.jwetherell.openmap.common.UTMPoint;
import java.util.LinkedHashMap;
import java.util.Map;
import net.osmand.LocationConvert;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.util.Algorithms;
public class PointDescription {
@ -172,6 +175,40 @@ public class PointDescription {
}
}
public static Map<String, String> getLocationData(MapActivity ctx, double lat, double lon, boolean sh) {
OsmandSettings settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
Map<String, String> results = new LinkedHashMap<>();
int f = settings.COORDINATES_FORMAT.get();
UTMPoint pnt = new UTMPoint(new LatLonPoint(lat, lon));
results.put(PointDescription.formatToHumanString(ctx, UTM_FORMAT), pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.easting) + " "+ ((long) pnt.northing));
try {
results.put(PointDescription.formatToHumanString(ctx, OLC_FORMAT), getLocationOlcName(lat, lon));
} catch (RuntimeException e) {
results.put(PointDescription.formatToHumanString(ctx, OLC_FORMAT), "0, 0");
}
if (f == PointDescription.UTM_FORMAT || f == PointDescription.OLC_FORMAT) {
f = PointDescription.FORMAT_DEGREES;
}
try {
results.put(PointDescription.formatToHumanString(ctx, f),
ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, LocationConvert.convert(lat, f),
LocationConvert.convert(lon, f)));
} catch (RuntimeException e) {
e.printStackTrace();
results.put(PointDescription.formatToHumanString(ctx, f),
ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, 0, 0));
}
final String httpUrl = "https://osmand.net/go?lat=" + (lat)
+ "&lon=" + (lon) + "&z=" + ctx.getMapView().getZoom();
results.put("URL", httpUrl);
return results;
}
public static String getLocationNamePlain(Context ctx, double lat, double lon) {
OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
int f = st.COORDINATES_FORMAT.get();

View file

@ -389,6 +389,10 @@ public class MenuBuilder {
}
}
protected void buildCoordinatesRow(View view) {
CollapsableView cv = getCollapsableTextView(app, true, "LatLon \n olc \n link \n utc");
}
protected void buildNearestPhotosRow(View view) {
if (!app.getSettings().isInternetConnectionAvailable()) {
return;

View file

@ -268,11 +268,19 @@ public abstract class MenuController extends BaseMenuController implements Colla
protected void addMyLocationToPlainItems(LatLon latLon) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
addPlainMenuItem(R.drawable.ic_action_get_my_location, null, PointDescription.getLocationName(mapActivity,
latLon.getLatitude(), latLon.getLongitude(), true).replaceAll("\n", " "), false, false, null);
}
}
protected void addMyLocationCollapsableView(LatLon latlon) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
int iconId = R.drawable.ic_action_get_my_location;
}
}
public PointDescription getPointDescription() {
return pointDescription;
}