How to calculate passed (driven) distance real time with android and without Google MAP API
I am trying to develop an android app for drivers. I want drivers would be able to check how many kilometers or meters passed (in realtime fashion). I know google map has API for that, but I want to use a free/ opensource API for my application. I prefer the most accurate algorithm or APIs.
I have tried google map API, HERE, TOMTOM and MapBox APIs.
See also questions close to this topic

app that shows jobs that i share in online database
I want to make android app that connected to online database and shows me the jobs that i will add it to the database in something like cards list. The user when click on the card it shows him the whole information about that job . Is there who can help me with this. I want to learn how to connect the app to the cloud and get information from it.

How to do a Room request inside of a class method?
I follower exactly this tutorial in order to implement Room in my Android project : https://www.techiediaries.com/androidroomtutorial/
I want to have a method inside my class Traject that takes a List of TrajectJson and add it to the Database using my trajectDao. But the problem is i cant access the database in my class method because it needs a context.
Is there a way to get the instance of my database without a context?

Query a DB with a String "Male or Female" if neither String is selected return all results
If a @Query string value doesn't return a result how do you return all the results from the column in Room?
Let's say I have list of students in my database, the database contains a Gender column, the entries in the column can be "Male" or "Female". I want to use one @Query that has the option to display all the students, the male students or the female students.
Reposiotry
// Constructor public Repository(Application application, String gender) { this.studentDao = db.StudentDao(); this.student = studentDAO.getStudents(gender); }
DAO
@Query("SELECT * FROM student_table WHERE mStudent =:gender or '%'") LiveData<List<StudentEntity>> getStudents(String gender or '%male'); If Male or Female weren't selected I want to see all the students return in the LiveData<List>.

Why is bitwise operator needed in this powerset generator?
I am currently following MITx's 6.00.2x, and we are asked to come up with a variant of power set generator of the one at the bottom.
But before I can work on the variant, I do not even understand what's going on with the given generator. Specifically:
 What does
(i >> j) % 2 == 1
, and in fact the wholefor j in range(N):
block do? I understand thati >> j
shifts the binary ofi
byj
, then returns the decimal representation of that shifted binary number. But I have absolutely no clue why binary is even needed in a powerset generator in the first place, let alone the necessity of this conditional. I understand that for any given set A a cardinality n, the cardinality of its powerset is 2**n  because for every subset of A every member is either in or not, and we repeat that for n times.
Is that what
for i in range(2**N):
is doing? i.e. going over 2**n subsets and either include or not include any given member of the set?
I tried running it with
items=['apple,'banana','orange']
anditems=[1,2,3]
, and both returned an empty list, which makes it all the more confusing.def powerSet(items): # generate all combinations of N items, items is a Python list N = len(items) # enumerate the 2**N possible combinations for i in range(2**N): combo = [] for j in range(N): # test bit jth of integer i if (i >> j) % 2 == 1: combo.append(items[j]) return combo
 What does

How to mention a function of functions in flowchart of an algorithm
I want to show a function in a flowchart which is itself a function of two other functions. How can I do that? Currently I have shown it as you see in figure. But I think it is not correct because it means that first sorting will be done and then two other functions (pareto... and crowding distance) which is not correct.
I want to show so that Sorting will be done by two functions: Pareto... and Crowding distance.
Flowchart including function Sort which itself is a function of two other functions

Given an arbitrary number of different letters, how can i find the shortest string that will contain all possible twoletter sequences?
I'm having trouble explaining because English is my second language and I'm bad at logic. I'll give examples to help.
If letters are ABC, the valid combinations I'm looking for are AB,AC,BA,BC,CA,CB. Simply combined into a string: ABACBABCCACB But there are still duplicates in that string. If I "compress" it, I get: ABACBCA
I'm not sure how to explain better, but I'm looking for an algorithm that would produce the "compressed" version.

Android studio terminal not showing
After I have tried to change the ADB shell location from cmd.exe to the .../sdk/platformtools in order to run ADB commands from Android Studio, the terminal is popping up and immediately closing back when I try to open it. PS. I have the latest version of Android Studio at the time of posting this question.

Debugger issue with Android Studio
Running into an issue when adding txtView1 onto my main activity resulting in an error saying "Can't bind to local 8700 for debugger" that's causing the app to crash. If I comment out the two txtView1 lines I don't recieve an error and the app will load properly. I forced quit the app, reran the emulator and restarted android studio but nothing has worked. Anyone have an idea how I can fix this?
public class MainActivity extends AppCompatActivity { private Button btnSubmit; private TextView txtView1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.newlayout); btnSubmit = (Button) findViewById(R.id.Button); txtView1 = (TextView) findViewById(R.id.txtView1); btnSubmit.setText(R.string.button_name); btnSubmit.setTextColor(Color.RED); } }

.xml file content changed in android studio
I'm a new android developer and I've been developing a project for months but for some reason today I Invalidated cache/restarted my project and don't know why all my drawable files content changed to
<component name="libraryTable"> <library name="Gradle: com.android.support:coordinatorlayout:28.0.0@aar"> <ANNOTATIONS> <root url="jar://$USER_HOME$/.gradle/caches/transforms2/files2.1/5d3c4801a740528a85d2e670b2dd23b7/coordinatorlayout28.0.0/annotations.zip!/" /> </ANNOTATIONS> <CLASSES> <root url="jar://$USER_HOME$/.gradle/caches/transforms2/files2.1/5d3c4801a740528a85d2e670b2dd23b7/coordinatorlayout28.0.0/jars/classes.jar!/" /> <root url="file://$USER_HOME$/.gradle/caches/transforms2/files2.1/5d3c4801a740528a85d2e670b2dd23b7/coordinatorlayout28.0.0/res" /> </CLASSES> <JAVADOC /> <SOURCES /> </library> </component>
and the every layout in my project has wiped out i.e BLANKED. how do I change it back? Help is appreciated!!

How to do Trilateration in java
I'm working on Trilateration to find position of unknown location, to find distance i use pathloss with constant is 2 like in the articles, i'm using 2 phone and one laptop as the transmitter and reference. Here's the code :
distance1 = (double) Math.pow(10, ((rssi.get(k)rssi1.get(a))/10*2));
rssi is rssi value 1m from reference and rssi1 is unknown location rssi.
And here's Trilateration code which formula is from This :
double r1 = Math.pow(distance1,2 ); double r2 = Math.pow(distance2,2 ); double r3 = Math.pow(distance3,2 ); double x1 = Math.pow(X1,2 ); double x2 = Math.pow(X2,2 ); double x3 = Math.pow(X3,2 ); double y1 = Math.pow(Y1,2 ); double y2 = Math.pow(Y2,2 ); double y3 = Math.pow(Y3,2 ); double A = r1  r2  x1+x2  y1+y2; double B = r2  r3  x2+x3  y2+y3; double C = ((2*X1)+(2*X2)); double D = ((2*Y1)+(2*Y2)); double E = ((2*X2)+(2*X3)); double F = ((2*Y2)+(2*Y3)); double x0 = (((A*F)(B*D))/((F*C)(E*D))); double y0 = (((A*E)(C*B))/((D*E)(C*F))); Log.v("x", String.valueOf(x0)); Log.v("y", String.valueOf(y0));
at first it gives quite accurate result but later the result is not change or even have a big error. I wonder why the result is not change is it because when do new calculation the previous result is not cleared or what? or there's some error in my code? I'm a little bit confuse, because there's more than one way to do trilateration from many source, like this:
double delta = 4*((X1X2)*(Y1Y3)(X1X3)*(Y1Y2)); double x0 = (1/delta) * ((2*A*(y1y3))(2*B*(y1y2))); double y0 = (1/delta) * ((2*B*(x1x2))(2*A*(x1x3)));
It's using delta to calculate which i don't understand where's it come from. I understand the first code which it's a linear equation. Is my constant to calculate distance is wrong? is there any code to do Trilateration with explanation of the formula? Also i trying to expanding time for receiving rssi signal and than average it, but the result is still bad.
Full code:
ArrayList<String> buildings; DatabaseHelper db; ArrayAdapter<String> arrayAdapter; ArrayList<PositionData> positionsData; String building; TextView result; TextView result2; TextView result3; Button locate; public void onCreate(Bundle saveInstanceState) { super.onCreate(saveInstanceState); setContentView(R.layout.locate_wifi); db = new DatabaseHelper(this); buildings = db.getBuildings_wifi(); locate = (Button) findViewById(R.id.locate); result = (TextView) findViewById(R.id.result); result2 = (TextView) findViewById(R.id.result2); result3 = (TextView) findViewById(R.id.result3); arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, buildings); locate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Autogenerated method stub Intent intent = new Intent(getApplicationContext(), Scan.class); intent.putExtra("isLearning", false); startActivityForResult(intent,0); } }); arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, buildings); // Set The Adapter if (buildings.size()==0) { Toast.makeText(this, "No building data available.", Toast.LENGTH_LONG).show(); locate.setEnabled(false); } else{ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCancelable(false); builder.setTitle("Choose building"); builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // the user clicked on colors[which] building = buildings.get(which); } }); builder.show(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { // TODO Autogenerated method stub if(resultCode==RESULT_OK){ PositionData positionData = (PositionData) intent .getSerializableExtra("PositionData"); positionsData=db.getWifiPositions(building); ArrayList<Router> wifis = db.getFriendlyWifis(building); HashMap<String, Double> rssi = positionData.getValues(); HashMap<String, Double> rssi1 = positionsData.get(0).getValues(); HashMap<String, Double> rssi2 = positionsData.get(1).getValues(); HashMap<String, Double> rssi3 = positionsData.get(2).getValues(); double X1 = positionsData.get(0).getX(); Double X2 = positionsData.get(1).getX(); Double X3 = positionsData.get(2).getX(); Double Y1 = positionsData.get(0).getY(); Double Y2 = positionsData.get(1).getY(); Double Y3 = positionsData.get(2).getY(); double distance1 = 0; double distance2 = 0; double distance3 = 0; for (String k : rssi.keySet()) { for (String a : rssi1.keySet()) { if (k.equals(a)) { Log.d("value",((Math.pow(10, ((rssi.get(k)rssi1.get(a))/10*2))))+""); distance1 = (double) Math.pow(10, ((rssi.get(k)rssi1.get(a))/10*2)); } } for (String b : rssi2.keySet()) { if (k.equals(b)) { Log.d("value2",((Math.pow(10, ((rssi.get(k)rssi2.get(b))/10*2))))+""); distance2 = (double) Math.pow(10, ((rssi.get(k)rssi2.get(b))/10*2)); } } for (String c : rssi3.keySet()) { if (k.equals(c)) { Log.d("value3",((Math.pow(10, ((rssi.get(k)rssi3.get(c))/10*2))))+""); distance3 = (double) Math.pow(10, ((rssi.get(k)rssi3.get(c))/10*2)); } } } double r1 = Math.pow(distance1,2 ); double r2 = Math.pow(distance2,2 ); double r3 = Math.pow(distance3,2 ); double x1 = Math.pow(X1,2 ); double x2 = Math.pow(X2,2 ); double x3 = Math.pow(X3,2 ); double y1 = Math.pow(Y1,2 ); double y2 = Math.pow(Y2,2 ); double y3 = Math.pow(Y3,2 ); double A = r1  r2  x1+x2  y1+y2; double B = r2  r3  x2+x3  y2+y3; //double delta = 4*((X1X2)*(Y1Y3)(X1X3)*(Y1Y2)); //double x0 = (1/delta) * ((2*A*(y1y3))(2*B*(y1y2))); //double y0 = (1/delta) * ((2*B*(x1x2))(2*A*(x1x3))); double C = ((2*X1)+(2*X2)); double D = ((2*Y1)+(2*Y2)); double E = ((2*X2)+(2*X3)); double F = ((2*Y2)+(2*Y3)); double x0 = (((A*F)(B*D))/((F*C)(E*D))); double y0 = (((A*E)(C*B))/((D*E)(C*F))); Log.v("x", String.valueOf(x0)); Log.v("y", String.valueOf(y0)); result.setText("X: "+ x0); result2.setText("Y: "+ y0); super.onActivityResult(requestCode, resultCode, intent); } } public class CustomOnItemSelectedListener implements AdapterView.OnItemSelectedListener { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { building = parent.getItemAtPosition(pos).toString(); locate.setEnabled(true); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Autogenerated method stub locate.setEnabled(false); } } }

Nearest data points depending on variable using Scipy cKDTree
I want to calculate the index of the point in a dataset, where each point depends on a variable t, in respect to the minimum distance to vector of points.
For the sake of understanding my dataset and vector is given in the form of
DataSet = [x_i + t*a_i, y_i + t*b_i] with i = 1,...,n and 0 < t < t_end Vector = [w_k, z_k] with k = 1,...,m
and the code should calculate for each point (w_k, z_k) the index and value of variable t of the point in the dataset with respect to minimal distance.
So far I wrote a simple code which calculates the index of the point in the dataset in respect to the minimum distance to a array of points.
The dataset and vector is given in the form of
DataSet = [x_i, y_i] with i = 1,...,n Vector = [w_k, z_k] with k = 1,...,m
and the code calculates for each point (w_k, z_k) in the vector the index of the point in the dataset with respect to minimal distance. The solution is an array
idx = [i_k] with i in [1, n] and k = 1,...,m.
The code for this is:
def _nearest_points(self, data, vector, n_neighbors): if self.data_tree is None: self.data_tree = cKDTree(data) dist, idx = self.data_tree.query(vector, k=n_neighbors, n_jobs=1) if n_neighbors > 1: dist = dist.mean(axis=1) k_means = self.data_tree.data[idx].mean(axis=1) _, idx = self.data_tree.query(k_means, k=1, n_jobs=1) nearest_points = self.data[idx] return idx, nearest_points
Is there an easy way to calculate the index vector for my original problem?

Arduino, HC SR04 distance sensor wrong output
my name is Dmitrij and I wanted to connect HCSR04 to Arduino so that I can measure the distance. The problem is that the sensor is sending 45 right results and then 56 wrong ones in a row.
I've tried to replace Arduino and the sensor it didn't help. At the end while I was writing this I kinda solved the problem. The sensor was getting 5 Volt from external powersuply module (https://i.imgur.com/Zjg22ka.png) after I connected sensor to Arduino 5V everything was working Fine. Is there a way to fix this somehow?
int echo = 8; int trig = 9; float duration, distance; void setup() { pinMode(echo, INPUT); pinMode(trig, OUTPUT); digitalWrite(trig, LOW); Serial.begin (9600); } void loop() { digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, LOW); duration = pulseIn(echo, HIGH); distance = (duration / 2) * 0.0344; Serial.print("Distance = "); Serial.print(distance); Serial.println(" cm"); delay(500);
}
Thats the output of the sensor when it was directed on the wall. The real Distance is around 1516 cm and i don't understand why does it output something else also.
Distance = 15.70 cm Distance = 15.70 cm Distance = 15.65 cm Distance = 15.70 cm Distance = 3.92 cm Distance = 2.25 cm Distance = 1.67 cm Distance = 0.48 cm Distance = 0.55 cm Distance = 6.73 cm Distance = 15.65 cm Distance = 15.65 cm Distance = 15.65 cm Distance = 15.65 cm Distance = 4.11 cm Distance = 2.27 cm Distance = 1.50 cm Distance = 0.50 cm Distance = 0.50 cm Distance = 6.33 cm
and so on.