use of get elevation in app

This commit is contained in:
afischerdev 2023-05-14 16:38:02 +02:00
parent 3c5ac660bf
commit 40b4794573
2 changed files with 119 additions and 93 deletions

View file

@ -6,7 +6,6 @@ import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Base64; import android.util.Base64;
import android.util.Log;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -24,6 +23,7 @@ import java.util.List;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import btools.router.OsmNodeNamed; import btools.router.OsmNodeNamed;
import btools.router.RoutingEngine;
public class BRouterService extends Service { public class BRouterService extends Service {
@ -39,6 +39,15 @@ public class BRouterService extends Service {
BRouterWorker worker = new BRouterWorker(); BRouterWorker worker = new BRouterWorker();
for (String key : params.keySet()) {
// Log.d("BS", "income " + key + " = " + params.get(key));
}
int engineMode = 0;
if (params.containsKey("engineMode")) {
engineMode = params.getInt("engineMode", 0);
}
// get base dir from private file // get base dir from private file
String baseDir = null; String baseDir = null;
InputStream configInput = null; InputStream configInput = null;
@ -56,34 +65,37 @@ public class BRouterService extends Service {
} }
worker.baseDir = baseDir; worker.baseDir = baseDir;
worker.segmentDir = new File(baseDir, "brouter/segments4"); worker.segmentDir = new File(baseDir, "brouter/segments4");
String remoteProfile = params.getString("remoteProfile", null);
if (remoteProfile == null) {
remoteProfile = checkForTestDummy(baseDir);
}
String errMsg = null; String errMsg = null;
if (remoteProfile != null) {
errMsg = getConfigForRemoteProfile(worker, baseDir, remoteProfile); if (engineMode == RoutingEngine.BROUTER_ENGINEMODE_ROUTING) {
} else if (params.containsKey("profile")) { String remoteProfile = params.getString("remoteProfile", null);
String profile = params.getString("profile");
worker.profileName = profile; if (remoteProfile == null) {
worker.profilePath = baseDir + "/brouter/profiles2/" + profile + ".brf"; remoteProfile = checkForTestDummy(baseDir);
worker.rawTrackPath = baseDir + "/brouter/modes/" + profile + "_rawtrack.dat"; }
if (!new File(worker.profilePath).exists()) {
errMsg = "Profile " + profile + " does not exists"; if (remoteProfile != null) {
} else { errMsg = getConfigForRemoteProfile(worker, baseDir, remoteProfile);
try { } else if (params.containsKey("profile")) {
readNogos(worker, baseDir); String profile = params.getString("profile");
} catch (Exception e) { worker.profileName = profile;
errMsg = e.getLocalizedMessage(); worker.profilePath = baseDir + "/brouter/profiles2/" + profile + ".brf";
worker.rawTrackPath = baseDir + "/brouter/modes/" + profile + "_rawtrack.dat";
if (!new File(worker.profilePath).exists()) {
errMsg = "Profile " + profile + " does not exists";
} else {
try {
readNogos(worker, baseDir);
} catch (Exception e) {
errMsg = e.getLocalizedMessage();
}
} }
} else {
errMsg = getConfigFromMode(worker, baseDir, params.getString("v"), params.getString("fast"));
} }
} else { } else {
errMsg = getConfigFromMode(worker, baseDir, params.getString("v"), params.getString("fast")); worker.profilePath = baseDir + "/brouter/profiles2/dummy.brf";
} }
if (errMsg != null) { if (errMsg != null) {
return errMsg; return errMsg;
} }
@ -109,7 +121,7 @@ public class BRouterService extends Service {
} }
return gpxMessage; return gpxMessage;
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
return iae.getMessage(); return iae.getMessage();
} }
} }
@ -121,7 +133,7 @@ public class BRouterService extends Service {
try { try {
String modesFile = baseDir + "/brouter/modes/serviceconfig.dat"; String modesFile = baseDir + "/brouter/modes/serviceconfig.dat";
br = new BufferedReader(new FileReader(modesFile)); br = new BufferedReader(new FileReader(modesFile));
for (;;) { for (; ; ) {
String line = br.readLine(); String line = br.readLine();
if (line == null) if (line == null)
break; break;
@ -244,7 +256,7 @@ public class BRouterService extends Service {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
try { try {
br = new BufferedReader(new FileReader(testdummy)); br = new BufferedReader(new FileReader(testdummy));
for (;;) { for (; ; ) {
String line = br.readLine(); String line = br.readLine();
if (line == null) if (line == null)
break; break;
@ -290,7 +302,6 @@ public class BRouterService extends Service {
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void onStart(Intent intent, int startId) { public void onStart(Intent intent, int startId) {
Log.d(getClass().getSimpleName(), "onStart()");
handleStart(intent, startId); handleStart(intent, startId);
} }

View file

@ -33,6 +33,12 @@ public class BRouterWorker {
public String profileParams; public String profileParams;
public String getTrackFromParams(Bundle params) { public String getTrackFromParams(Bundle params) {
int engineMode = 0;
if (params.containsKey("engineMode")) {
engineMode = params.getInt("engineMode", 0);
}
String pathToFileResult = params.getString("pathToFileResult"); String pathToFileResult = params.getString("pathToFileResult");
if (pathToFileResult != null) { if (pathToFileResult != null) {
@ -97,7 +103,7 @@ public class BRouterWorker {
waypoints = readPositions(params); waypoints = readPositions(params);
} }
if (params.containsKey("lonlats")) { if (params.containsKey("lonlats")) {
waypoints = readLonlats(params); waypoints = readLonlats(params, engineMode);
} }
if (waypoints == null) return "no pts "; if (waypoints == null) return "no pts ";
@ -141,11 +147,6 @@ public class BRouterWorker {
} }
} }
int engineMode = 0;
if (params.containsKey("engineMode")) {
engineMode = params.getInt("engineMode", 0);
}
try { try {
writeTimeoutData(rc); writeTimeoutData(rc);
} catch (Exception e) { } catch (Exception e) {
@ -155,62 +156,69 @@ public class BRouterWorker {
cr.quite = true; cr.quite = true;
cr.doRun(maxRunningTime); cr.doRun(maxRunningTime);
// store new reference track if any if (engineMode == RoutingEngine.BROUTER_ENGINEMODE_ROUTING) {
// (can exist for timed-out search) // store new reference track if any
if (cr.getFoundRawTrack() != null) { // (can exist for timed-out search)
try { if (cr.getFoundRawTrack() != null) {
cr.getFoundRawTrack().writeBinary(rawTrackPath); try {
} catch (Exception e) { cr.getFoundRawTrack().writeBinary(rawTrackPath);
} } catch (Exception e) {
}
if (cr.getErrorMessage() != null) {
return cr.getErrorMessage();
}
String format = params.getString("trackFormat");
int writeFromat = OUTPUT_FORMAT_GPX;
if (format != null) {
if ("kml".equals(format)) writeFromat = OUTPUT_FORMAT_KML;
if ("json".equals(format)) writeFromat = OUTPUT_FORMAT_JSON;
}
OsmTrack track = cr.getFoundTrack();
if (track != null) {
if (params.containsKey("exportWaypoints")) {
track.exportWaypoints = (params.getInt("exportWaypoints", 0) == 1);
}
if (pathToFileResult == null) {
switch (writeFromat) {
case OUTPUT_FORMAT_GPX:
return track.formatAsGpx();
case OUTPUT_FORMAT_KML:
return track.formatAsKml();
case OUTPUT_FORMAT_JSON:
return track.formatAsGeoJson();
default:
return track.formatAsGpx();
} }
}
if (cr.getErrorMessage() != null) {
return cr.getErrorMessage();
} }
try {
switch (writeFromat) { String format = params.getString("trackFormat");
case OUTPUT_FORMAT_GPX: int writeFromat = OUTPUT_FORMAT_GPX;
track.writeGpx(pathToFileResult); if (format != null) {
break; if ("kml".equals(format)) writeFromat = OUTPUT_FORMAT_KML;
case OUTPUT_FORMAT_KML: if ("json".equals(format)) writeFromat = OUTPUT_FORMAT_JSON;
track.writeKml(pathToFileResult); }
break;
case OUTPUT_FORMAT_JSON: OsmTrack track = cr.getFoundTrack();
track.writeJson(pathToFileResult); if (track != null) {
break; if (params.containsKey("exportWaypoints")) {
default: track.exportWaypoints = (params.getInt("exportWaypoints", 0) == 1);
track.writeGpx(pathToFileResult); }
break; if (pathToFileResult == null) {
switch (writeFromat) {
case OUTPUT_FORMAT_GPX:
return track.formatAsGpx();
case OUTPUT_FORMAT_KML:
return track.formatAsKml();
case OUTPUT_FORMAT_JSON:
return track.formatAsGeoJson();
default:
return track.formatAsGpx();
}
}
try {
switch (writeFromat) {
case OUTPUT_FORMAT_GPX:
track.writeGpx(pathToFileResult);
break;
case OUTPUT_FORMAT_KML:
track.writeKml(pathToFileResult);
break;
case OUTPUT_FORMAT_JSON:
track.writeJson(pathToFileResult);
break;
default:
track.writeGpx(pathToFileResult);
break;
}
} catch (Exception e) {
return "error writing file: " + e;
} }
} catch (Exception e) {
return "error writing file: " + e;
} }
} else { // get other infos
if (cr.getErrorMessage() != null) {
return cr.getErrorMessage();
}
return cr.getFoundInfo();
} }
return null; return null;
} }
@ -233,25 +241,31 @@ public class BRouterWorker {
wplist.add(n); wplist.add(n);
} }
if (wplist.get(0).name.startsWith("via")) wplist.get(0).name = "from"; if (wplist.get(0).name.startsWith("via")) wplist.get(0).name = "from";
if (wplist.get(wplist.size() - 1).name.startsWith("via")) wplist.get(wplist.size() - 1).name = "to"; if (wplist.get(wplist.size() - 1).name.startsWith("via"))
wplist.get(wplist.size() - 1).name = "to";
return wplist; return wplist;
} }
private List<OsmNodeNamed> readLonlats(Bundle params) { private List<OsmNodeNamed> readLonlats(Bundle params, int mode) {
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>(); List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
String lonLats = params.getString("lonlats"); String lonLats = params.getString("lonlats");
if (lonLats == null) throw new IllegalArgumentException("lonlats parameter not set"); if (lonLats == null) throw new IllegalArgumentException("lonlats parameter not set");
String[] coords = lonLats.split("\\|"); String[] coords;
if (coords.length < 2) if (mode == 0) {
throw new IllegalArgumentException("we need two lat/lon points at least!"); coords = lonLats.split("\\|");
if (coords.length < 2)
throw new IllegalArgumentException("we need two lat/lon points at least!");
} else {
coords = new String[1];
coords[0] = lonLats;
}
for (int i = 0; i < coords.length; i++) { for (int i = 0; i < coords.length; i++) {
String[] lonLat = coords[i].split(","); String[] lonLat = coords[i].split(",");
if (lonLat.length < 2) if (lonLat.length < 2)
throw new IllegalArgumentException("we need two lat/lon points at least!"); throw new IllegalArgumentException("we need a lat and lon point at least!");
wplist.add(readPosition(lonLat[0], lonLat[1], "via" + i)); wplist.add(readPosition(lonLat[0], lonLat[1], "via" + i));
if (lonLat.length > 2) { if (lonLat.length > 2) {
if (lonLat[2].equals("d")) { if (lonLat[2].equals("d")) {
@ -263,7 +277,8 @@ public class BRouterWorker {
} }
if (wplist.get(0).name.startsWith("via")) wplist.get(0).name = "from"; if (wplist.get(0).name.startsWith("via")) wplist.get(0).name = "from";
if (wplist.get(wplist.size() - 1).name.startsWith("via")) wplist.get(wplist.size() - 1).name = "to"; if (wplist.get(wplist.size() - 1).name.startsWith("via"))
wplist.get(wplist.size() - 1).name = "to";
return wplist; return wplist;
} }