|
Having the coordinates from Android Sensor and try to calculate the distance in Excel according to:
http://andrew.hedges.name/experiments/haversine/
dlon = lon2 - lon1
dlat = lat2 - lat1
a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
c = 2 * atan2( sqrt(a), sqrt(1-a) )
d = R * c (where R is the radius of the Earth)
Enter my two Locations in the calculator (link above) shows me the right result, it is about 6m.
When I calculate it by Excel I get 20Km instead of 6 meters
I'm strongly assuming that I mix up rad vs. degree but I do not find where I'm wrong.
Excel trigonometric functions expect everything in rad so I adjust lon1, lon2, lat1, lat2 first into rad...
Where I could be wrong, any idea?
Thank you in advance.
N.B: I'm also not sure whether it is ok to use the sensor decimal values directly for trigonometric function, maybe this is the key Point.
[Edit]
c allways Shows me something very near PI, e.g. 3.14159145
modified 19-Jan-21 21:04pm.
|
|
|
|
|
0x01AA wrote: Where I could be wrong Just about anywhere. Does this have something to do with Android programming?
|
|
|
|
|
Yes it has and no. The Lib I'm using is Embarcardero Fire-ThisAndThat. Some of the Sensors are Android specific supported
So where you suggest to ask the question?
Sorry, but .... grrrr
AND PLEASE DO NOT MARK YOUR COMMENT AS ANSWER TO EARN POINTS!!
SILLY DOWNVOTER!
SORRY, BRUNO
modified 19-Jan-21 21:04pm.
|
|
|
|
|
0x01AA wrote: Having the coordinates from Android Sensor and try to calculate the distance in Excel according to: So where exactly is the Android code issue?
Sorry but ?
|
|
|
|
|
If you are not familar with it why you bother about it?
DOWNVOTE TWO TIMES, SORRY YOU ARE AN A*H*. Now please Report me as abuser!
modified 19-Jan-21 21:04pm.
|
|
|
|
|
0x01AA wrote: If you are not familar with it why you bother about it? Richard is more familiar with "it" than most folks here (combined). Don't fault him for you not asking the correct question.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
He is familiar with a lot of things, I agree! But as soon he is not familiar with a subject he is Stalking the one who is asking... and my Feeling is, that he is Stalking especally me.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
0x01AA wrote: ...he is Stalking especally me. So he is pursuing or approaching you stealthily? Really?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
0x01AA wrote: and my Feeling is, that he is Stalking especally me. Be afraid, be very afraid.
|
|
|
|
|
0x01AA wrote: So where you suggest to ask the question? Maybe the site from where you obtained the Embarcardero Fire-ThisAndThat lib.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
0x01AA wrote: Having the coordinates from Android Sensor... What coordinates?
0x01AA wrote: ...and try to calculate the distance... From/to what?
0x01AA wrote:
Enter my two Locations in the calculator (link above) shows me the right result, it is about 6m.
When I calculate it by Excel I get 20Km instead of 6 meters So then there's a difference between the two formulas. Since you've only shown one, how could anyone possibly guess as to what is wrong?
0x01AA wrote:
I'm strongly assuming that I mix up rad vs. degree but I do not find where I'm wrong.
Excel trigonometric functions expect everything in rad so I adjust lon1, lon2, lat1, lat2 first into rad... It's either degrees or radians. If you've tried both and neither produce the correct result, then that's not the (only) problem.
0x01AA wrote:
N.B: I'm also not sure whether it is ok to use the sensor decimal values directly for trigonometric function... Are they expecting floating-point values? If so, then you must use the "decimal values."
All of this aside, where's the Android issue?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Quote: Are they expecting floating-point values? If so, then you must use the "decimal values."
Expressed in "Expressed in decimal degrees" as pointed out by the link I gave.
Quote: It's either degrees or radians
Assume, I'm quite familiar to distinguish between them;)
The curious Thing:
2.0 * ArcTan2(Sqrt(1.0 - xA), Sqrt(xA));
instead of
2.0 * ArcTan2(Sqrt(xA), Sqrt(1.0 - xA));
solved the cross check with Excel for the Moment. While the second one still is ok in c++
Why it solved it? For this I Need to bring back first trigo back into my mind.
Quote: All of this aside, where's the Android issue
Do you program for programming sake or do you even program to solve a task?
Ok, it is not Android specific, but while working with Android at the Moment, I thought I will ask this here. Now hang me higher because of this delinquency
modified 19-Jan-21 21:04pm.
|
|
|
|
|
0x01AA wrote: Why it solved it? Because the two function signatures are different. In Excel, it is:
ATAN2(x,y) and for JavaScript, it is:
ATAN2(y,x)
0x01AA wrote: Ok, it is not Android specific, but while working with Android at the Moment, I thought I will ask this here. Perhaps here would be a better choice.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
modified 29-Mar-17 10:21am.
|
|
|
|
|
Thank you for the link. I was not aware that this exists.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Actually i had created database now i want to retrive it on list items click how should i connect both of this apps please kindly give attention in this.
|
|
|
|
|
It rather depends on what database you are using, and how the data is structured.
|
|
|
|
|
we are going to develope an app that are realted to the health care.we need som ecode and features that you know and it can increase the quality of our app
|
|
|
|
|
Member 13073018 wrote: som ecode and features
Perhaps your app could extend to telepathic powers, reading the mind of anybody using it?!
Think about it... how can anybody offer any useful advice when you ask such a vague question. Please give us some information about what you want to achieve. I also suggest that unless you've developed an app or two before, don't waste your time looking to build one from random samples that you might be able to pull together. You really need to be realistic about what can be done starting from where you are.
|
|
|
|
|
So, I built this HTML5 multiplayer online game, https://SpaceBlaster.io, and now I want to put it in the Google Play Store. It already works on mobile and computer browser. Can I just slap the HTML5 code into a cordova project and it will work as an android app? How does the app know which Websocket server to connect to? Have any of you done this sort of thing before? I'm kind of at a loss as to how to proceed. I already have one cordova app in the Play Store, so I'm familiar with that routine, but that was a standalone app designed from the beginning to be just a mobile app.
I hope that all wasn't too confusing.
Thanks in advance!
You can't win.
You can't break even.
You can't quit.
You're welcome.
|
|
|
|
|
I apologize for the vague title of this thread. I am a C# developer and I am having some issues with trying to understand the way things are done in Java / Android.
private boolean EverPlayedNextLevel(final int Level){
locked = false;
String Uid = acct.getId();
DatabaseReference db = FirebaseDatabase.getInstance().getReference();
Query query = db.child("levels/uid/" + Uid + "/" + Level);
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
locked = ((long)dataSnapshot.getValue() == -1);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return locked;
}
The Boolean variable locked is a class level variable. Notice that I set it to false at the beginning of the method. If I set a breakpoint at the closing brace of the onDataChange "inner" method and
((long)dataSnapshot.getValue() == -1); returns true, then locked is of course true. But the method EverPlayedNextLevel still returns false. How should I deal with this? I don't understand what is going on. I want EverPlayedNextLevel to return true if
((long)dataSnapshot.getValue() == -1); evaluates to true.
|
|
|
|
|
You are casting your number to a long. What happens when you cast -1 to a long?
Forget my word , long is signed.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
modified 23-Feb-17 15:31pm.
|
|
|
|
|
Thanks Eddy. I did do some research on Long after your comment, but yes, my comparison is working with long.
|
|
|
|
|
I'm not an Android and Java expert but it looks like onDataChange is an asynchronous function which is executed in a different thread.
Then EverPlayedNextLevel might return before locked has been set.
A quick research before hitting the post button found this very similar problem:
android - Return value from valueEventListener java - Stack Overflow[^]
|
|
|
|
|
You are correct, it's an event handler.
|
|
|
|
|
Thank you Jochen. Sorry it took so long for me to get back to you. I have been working a lot. I did not end up using the method that was used in that post, but it did lead me to the answer, so I will mark your post as the answer.
What I did is rework my code so that instead of trying to return a value from the asynchronous method, I simply call a new method if the condition matches what I am looking for.
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Spacecraft listItem = (Spacecraft) lv.getItemAtPosition(position);
Level = listItem.getLevel();
EverPlayedNextLevel();
}
});
Next, make sure the point value for this level is not -1. -1 means the level is locked.
private void EverPlayedNextLevel(){
String Uid = acct.getId();
DatabaseReference db = FirebaseDatabase.getInstance().getReference();
Query query = db.child("levels/uid/" + Uid + "/" + Level);
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if((long)dataSnapshot.getValue() != -1)
LaunchMainActivity();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
So if it is not -1, launch the main activity by calling another method.
Thanks for your help.
|
|
|
|