Fix simulation in tunnel (too quick now)

This commit is contained in:
vshcherb 2013-12-18 10:55:08 +01:00
parent fa16343f3d
commit 847c8e8d44
3 changed files with 112 additions and 120 deletions

View file

@ -447,6 +447,10 @@ public class MapUtils {
// return measuredDist(x1, y1, x2, y2);
}
public static double measuredDist31(int x1, int y1, int x2, int y2) {
return getDistance(MapUtils.get31LatitudeY(y1), MapUtils.get31LongitudeX(x1), MapUtils.get31LatitudeY(y2), MapUtils.get31LongitudeX(x2));
}
public static double squareDist31TileMetric(int x1, int y1, int x2, int y2) {
// translate into meters
double dy = convert31YToMeters(y1, y2);

View file

@ -32,13 +32,13 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
public class GPXUtilities {
public final static Log log = PlatformUtil.getLog(GPXUtilities.class);
private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$
private final static NumberFormat latLonFormat = new DecimalFormat("0.00#####", new DecimalFormatSymbols(new Locale("EN", "US")));
private final static NumberFormat latLonFormat = new DecimalFormat("0.00#####", new DecimalFormatSymbols(
new Locale("EN", "US")));
public static class GPXExtensions {
Map<String, String> extensions = null;
@ -71,7 +71,8 @@ public class GPXUtilities {
public double speed = 0;
public double hdop = Double.NaN;
public WptPt() {}
public WptPt() {
}
public WptPt(double lat, double lon, long time, double ele, double speed, double hdop) {
this.lat = lat;
@ -170,10 +171,8 @@ public class GPXUtilities {
return points.isEmpty() && routes.isEmpty();
}
}
public static String writeGpxFile(File fout, GPXFile file, ClientContext ctx) {
FileOutputStream output = null;
try {
@ -193,8 +192,8 @@ public class GPXUtilities {
}
serializer.attribute(null, "xmlns", "http://www.topografix.com/GPX/1/1"); //$NON-NLS-1$ //$NON-NLS-2$
serializer.attribute(null, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
serializer.attribute(null, "xsi:schemaLocation", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");
serializer.attribute(null, "xsi:schemaLocation",
"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");
for (Track track : file.tracks) {
serializer.startTag(null, "trk"); //$NON-NLS-1$
@ -242,8 +241,7 @@ public class GPXUtilities {
} catch (IOException e) {
log.error("Error saving gpx", e); //$NON-NLS-1$
return ctx.getString(R.string.error_occurred_saving_gpx);
}
finally {
} finally {
if (output != null) {
try {
output.close();
@ -295,7 +293,6 @@ public class GPXUtilities {
writeExtensions(serializer, p);
}
public static class GPXFileResult {
public ArrayList<List<Location>> locations = new ArrayList<List<Location>>();
public ArrayList<WptPt> wayPoints = new ArrayList<WptPt>();
@ -317,7 +314,6 @@ public class GPXUtilities {
}
}
private static String readText(XmlPullParser parser, String key) throws XmlPullParserException, IOException {
int tok;
String text = null;
@ -351,7 +347,8 @@ public class GPXUtilities {
return res;
} finally {
try {
if (fis != null) fis.close();
if (fis != null)
fis.close();
} catch (IOException ignore) {
// ignore
}
@ -542,8 +539,6 @@ public class GPXUtilities {
return new InputStreamReader(bis, "UTF-8");
}
private static WptPt parseWptAttributes(XmlPullParser parser) {
WptPt wpt = new WptPt();
try {
@ -576,5 +571,4 @@ public class GPXUtilities {
}
}

View file

@ -102,12 +102,6 @@ public class OsmAndLocationProvider implements SensorEventListener {
private OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS;
private OsmandPreference<Boolean> USE_FILTER_FOR_COMPASS;
private static double squareDist(int x1, int y1, int x2, int y2) {
// translate into meters
double dy = MapUtils.convert31YToMeters(y1, y2);
double dx = MapUtils. convert31XToMeters(x1, x2);
return dx * dx + dy * dy;
}
public class SimulationProvider {
private int currentRoad;
@ -137,7 +131,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
RouteDataObject obj = road.getObject();
QuadPoint proj = MapUtils.getProjectionPoint31(px, py, obj.getPoint31XTile(j-1), obj.getPoint31YTile(j-1),
obj.getPoint31XTile(j), obj.getPoint31YTile(j));
double dd = squareDist((int)proj.x, (int)proj.y, px, py);
double dd = MapUtils.squareRootDist31((int)proj.x, (int)proj.y, px, py);
if (dd < dist) {
dist = dd;
currentRoad = i;
@ -166,7 +160,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
st31x = (int) currentPoint.x;
st31y = (int) currentPoint.y;
}
double dd = MapUtils.squareRootDist31(st31x, st31y, end31x, end31y);
double dd = MapUtils.measuredDist31(st31x, st31y, end31x, end31y);
if(meters > dd && !last){
meters -= dd;
} else {