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,14 +65,15 @@ public class BRouterService extends Service {
}
worker.baseDir = baseDir;
worker.segmentDir = new File(baseDir, "brouter/segments4");
String errMsg = null;
if (engineMode == RoutingEngine.BROUTER_ENGINEMODE_ROUTING) {
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")) {
@ -83,7 +93,9 @@ public class BRouterService extends Service {
} else {
errMsg = getConfigFromMode(worker, baseDir, params.getString("v"), params.getString("fast"));
}
} else {
worker.profilePath = baseDir + "/brouter/profiles2/dummy.brf";
}
if (errMsg != null) {
return errMsg;
}
@ -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,6 +156,7 @@ public class BRouterWorker {
cr.quite = true;
cr.doRun(maxRunningTime);
if (engineMode == RoutingEngine.BROUTER_ENGINEMODE_ROUTING) {
// store new reference track if any
// (can exist for timed-out search)
if (cr.getFoundRawTrack() != null) {
@ -212,6 +214,12 @@ public class BRouterWorker {
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("\\|");
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;
}