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.RemoteException;
import android.util.Base64;
import android.util.Log;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
@ -24,6 +23,7 @@ import java.util.List;
import java.util.zip.GZIPOutputStream;
import btools.router.OsmNodeNamed;
import btools.router.RoutingEngine;
public class BRouterService extends Service {
@ -39,6 +39,15 @@ public class BRouterService extends Service {
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
String baseDir = null;
InputStream configInput = null;
@ -56,34 +65,37 @@ public class BRouterService extends Service {
}
worker.baseDir = baseDir;
worker.segmentDir = new File(baseDir, "brouter/segments4");
String remoteProfile = params.getString("remoteProfile", null);
if (remoteProfile == null) {
remoteProfile = checkForTestDummy(baseDir);
}
String errMsg = null;
if (remoteProfile != null) {
errMsg = getConfigForRemoteProfile(worker, baseDir, remoteProfile);
} else if (params.containsKey("profile")) {
String profile = params.getString("profile");
worker.profileName = profile;
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();
if (engineMode == RoutingEngine.BROUTER_ENGINEMODE_ROUTING) {
String remoteProfile = params.getString("remoteProfile", null);
if (remoteProfile == null) {
remoteProfile = checkForTestDummy(baseDir);
}
if (remoteProfile != null) {
errMsg = getConfigForRemoteProfile(worker, baseDir, remoteProfile);
} else if (params.containsKey("profile")) {
String profile = params.getString("profile");
worker.profileName = profile;
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 {
errMsg = getConfigFromMode(worker, baseDir, params.getString("v"), params.getString("fast"));
worker.profilePath = baseDir + "/brouter/profiles2/dummy.brf";
}
if (errMsg != null) {
return errMsg;
}
@ -109,7 +121,7 @@ public class BRouterService extends Service {
}
return gpxMessage;
} catch (IllegalArgumentException iae) {
return iae.getMessage();
return iae.getMessage();
}
}
@ -121,7 +133,7 @@ public class BRouterService extends Service {
try {
String modesFile = baseDir + "/brouter/modes/serviceconfig.dat";
br = new BufferedReader(new FileReader(modesFile));
for (;;) {
for (; ; ) {
String line = br.readLine();
if (line == null)
break;
@ -244,7 +256,7 @@ public class BRouterService extends Service {
StringBuilder sb = new StringBuilder();
try {
br = new BufferedReader(new FileReader(testdummy));
for (;;) {
for (; ; ) {
String line = br.readLine();
if (line == null)
break;
@ -290,7 +302,6 @@ public class BRouterService extends Service {
@Override
@SuppressWarnings("deprecation")
public void onStart(Intent intent, int startId) {
Log.d(getClass().getSimpleName(), "onStart()");
handleStart(intent, startId);
}

View file

@ -33,6 +33,12 @@ public class BRouterWorker {
public String profileParams;
public String getTrackFromParams(Bundle params) {
int engineMode = 0;
if (params.containsKey("engineMode")) {
engineMode = params.getInt("engineMode", 0);
}
String pathToFileResult = params.getString("pathToFileResult");
if (pathToFileResult != null) {
@ -97,7 +103,7 @@ public class BRouterWorker {
waypoints = readPositions(params);
}
if (params.containsKey("lonlats")) {
waypoints = readLonlats(params);
waypoints = readLonlats(params, engineMode);
}
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 {
writeTimeoutData(rc);
} catch (Exception e) {
@ -155,62 +156,69 @@ public class BRouterWorker {
cr.quite = true;
cr.doRun(maxRunningTime);
// store new reference track if any
// (can exist for timed-out search)
if (cr.getFoundRawTrack() != null) {
try {
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 (engineMode == RoutingEngine.BROUTER_ENGINEMODE_ROUTING) {
// store new reference track if any
// (can exist for timed-out search)
if (cr.getFoundRawTrack() != null) {
try {
cr.getFoundRawTrack().writeBinary(rawTrackPath);
} catch (Exception e) {
}
}
if (cr.getErrorMessage() != null) {
return cr.getErrorMessage();
}
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;
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();
}
}
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;
}
@ -233,25 +241,31 @@ public class BRouterWorker {
wplist.add(n);
}
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;
}
private List<OsmNodeNamed> readLonlats(Bundle params) {
private List<OsmNodeNamed> readLonlats(Bundle params, int mode) {
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
String lonLats = params.getString("lonlats");
if (lonLats == null) throw new IllegalArgumentException("lonlats parameter not set");
String[] coords = lonLats.split("\\|");
if (coords.length < 2)
throw new IllegalArgumentException("we need two lat/lon points at least!");
String[] coords;
if (mode == 0) {
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++) {
String[] lonLat = coords[i].split(",");
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));
if (lonLat.length > 2) {
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(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;
}