pr fix
This commit is contained in:
parent
d700221eb0
commit
5bf210883d
3 changed files with 29 additions and 40 deletions
|
@ -121,38 +121,6 @@ public class MapUtils {
|
|||
return getDistance(l1.getLatitude(), l1.getLongitude(), l2.getLatitude(), l2.getLongitude());
|
||||
}
|
||||
|
||||
public static float[] getDistanceAndBearing(double lat1, double lon1, double lat2, double lon2) {
|
||||
float[] db = new float[2];
|
||||
Location l1 = new Location("");
|
||||
Location l2 = new Location("");
|
||||
l1.setLatitude(lat1);
|
||||
l1.setLongitude(lon1);
|
||||
l2.setLatitude(lat2);
|
||||
l2.setLongitude(lon2);
|
||||
return new float[]{l1.distanceTo(l2), l1.bearingTo(l2)};
|
||||
}
|
||||
|
||||
public static float getBearingToPoint(double lat1, double lon1, double lat2, double lon2) {
|
||||
Location l1 = new Location("");
|
||||
Location l2 = new Location("");
|
||||
l1.setLatitude(lat1);
|
||||
l1.setLongitude(lon1);
|
||||
l2.setLatitude(lat2);
|
||||
l2.setLongitude(lon2);
|
||||
return getBearingToPoint(l1, l2);
|
||||
}
|
||||
|
||||
public static float getBearingToPoint(Location l1, double lat, double lon) {
|
||||
Location l2 = new Location("");
|
||||
l2.setLatitude(lat);
|
||||
l2.setLongitude(lon);
|
||||
return getBearingToPoint(l1, l2);
|
||||
}
|
||||
|
||||
public static float getBearingToPoint(Location l1, Location l2) {
|
||||
return l1.bearingTo(l2);
|
||||
}
|
||||
|
||||
public static double checkLongitude(double longitude) {
|
||||
if (longitude >= MIN_LONGITUDE && longitude <= MAX_LONGITUDE) {
|
||||
return longitude;
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.graphics.Paint;
|
|||
import android.graphics.Path;
|
||||
import android.graphics.PointF;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.QuadPoint;
|
||||
|
@ -206,7 +207,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
WptPt lastPoint = editingCtx.getPoints().get(editingCtx.getPointsCount() - 1);
|
||||
LatLon centerLatLon = tb.getCenterLatLon();
|
||||
distance = (float) MapUtils.getDistance(lastPoint.lat, lastPoint.lon, centerLatLon.getLatitude(), centerLatLon.getLongitude());
|
||||
bearing = MapUtils.getBearingToPoint(lastPoint.lat, lastPoint.lon, centerLatLon.getLatitude(), centerLatLon.getLongitude());
|
||||
bearing = getLocationFromLL(lastPoint.lat, lastPoint.lon).bearingTo(getLocationFromLL(centerLatLon.getLatitude(), centerLatLon.getLongitude()));
|
||||
}
|
||||
measureDistanceToCenterListener.onMeasure(distance, bearing);
|
||||
}
|
||||
|
@ -413,6 +414,13 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
|||
return false;
|
||||
}
|
||||
|
||||
private Location getLocationFromLL(double lat, double lon) {
|
||||
Location l = new Location("");
|
||||
l.setLatitude(lat);
|
||||
l.setLongitude(lon);
|
||||
return l;
|
||||
}
|
||||
|
||||
interface OnSingleTapListener {
|
||||
|
||||
void onAddPoint();
|
||||
|
|
|
@ -91,22 +91,28 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementTool
|
|||
holder.descr.setText(pointDesc);
|
||||
} else {
|
||||
String text = "";
|
||||
Location l1;
|
||||
Location l2;
|
||||
if (pos < 1) {
|
||||
text = mapActivity.getString(R.string.shared_string_control_start);
|
||||
Location l1 = mapActivity.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
|
||||
|
||||
mapActivity.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
|
||||
if (mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null) {
|
||||
text = text + BULLET + OsmAndFormatter
|
||||
.getFormattedAzimuth(MapUtils.getBearingToPoint(l1, points.get(0).lat, points.get(0).lon));
|
||||
l1 = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
|
||||
l2 = getLocationFromLL(points.get(0).lat, points.get(0).lon);
|
||||
text = text
|
||||
+ BULLET + OsmAndFormatter.getFormattedDistance(l1.distanceTo(l2), mapActivity.getMyApplication())
|
||||
+ BULLET + OsmAndFormatter.getFormattedAzimuth(l1.bearingTo(l2));
|
||||
}
|
||||
holder.descr.setText(text);
|
||||
} else {
|
||||
float dist = 0;
|
||||
for (int i = 1; i <= pos; i++) {
|
||||
float[] dab = MapUtils.getDistanceAndBearing(points.get(i - 1).lat, points.get(i - 1).lon,
|
||||
points.get(i).lat, points.get(i).lon);
|
||||
dist += dab[0];
|
||||
l1 = getLocationFromLL(points.get(i - 1).lat, points.get(i - 1).lon);
|
||||
l2 = getLocationFromLL(points.get(i).lat, points.get(i).lon);
|
||||
dist += l1.distanceTo(l2);
|
||||
text = OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication())
|
||||
+ BULLET + OsmAndFormatter.getFormattedAzimuth(dab[1]);
|
||||
+ BULLET + OsmAndFormatter.getFormattedAzimuth(l1.bearingTo(l2));
|
||||
}
|
||||
holder.descr.setText(text);
|
||||
}
|
||||
|
@ -143,6 +149,13 @@ public class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementTool
|
|||
});
|
||||
}
|
||||
|
||||
private Location getLocationFromLL(double lat, double lon) {
|
||||
Location l = new Location("");
|
||||
l.setLatitude(lat);
|
||||
l.setLongitude(lon);
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return points.size();
|
||||
|
|
Loading…
Reference in a new issue