2017년 8월 5일 토요일

Use compass to point to specific direction using coordinates


Hi I've just started with App Inventor.

I had a question about using a compass direction that points to one specific Adress or coordinate instead of just the north. 
I would like to make a compass which point to Central Station of Amsterdam
I use the following website when making the compass.

http://puravidaapps.com/snippets.php#2compass
compass.aia

--
You are out of luck.  You can not use the OrientationSensor to point to anything other than North.

To point to your train station, you will need the LocationSensor, use it to determine current location and calculate the bearing from the current location to the train station using the Math blocks.
c
You will probably use the Haversine algorithm to calculate distance from the station (if you need that too) and use the algorithms at the Aviation Formulary to calculate the bearing    find it here:   http://williams.best.vwh.net/avform.htm   

You probably can use the Compass rose to do the pointing but you will have to use the  forumlas at the Aviation Formulary algorithm to calculate the bearing.   
The Where is My Car and Location Sensor tutorials will get you started.

Try some blocks, if you get stuck, return here and someone might be able to give you advice.

--
you might be interested in this App Inventor Classic snippet https://groups.google.com/d/msg/programming-with-app-inventor/gW1Y0JGz-GI/qyLMqcL1NokJ


--
I tried the results of Engberg into App Inventor 2. 

I've also read almost everything for advice in other posts 

Converting I have tried almost all the options I could think of. 
Is there anyone who can help here with me.

I added print screen of how far I am. 
The compass will run, but not in the right direction. 

But I do not know what I'm doing wrong




--
Perhaps try

to be compatible with the example .... or was there a reason you added instead of subtracting as in the example?

Also, be aware, if your device is near your PC or other source of magnetism or a large metal object, the Orientation sensor will provide erroneous readings... it is a type of compass after all affected by metallic objects etc.

--
that's a mistake. 
Because I have tried so many possibilities that I've Overlooked that i added.

y wil try, can you see if my varibales are oke?

--
Y changed it in substracting. 
it stil only points to the north.

when y use fixed values then it points to the right direction.
when y use varibles it's like if not responding to calculation.

--
when y use fixed values then it points to the right direction.

OK, then it works, just using simple trig.


when y use variables it's like if not responding to calculation.

I can not see how you enter those variables.  One possibility is your latitude and or longitude require a negative sign (-) and you forgot to include it in the list or whatever.
Can you show an image of how you are changing the latitude/longitude variable for the 'fixed' points.  Since using fixed values works correctly, you have an issue in 
your list picker or  however you are selecting the fixed points.    You may have mixed up the lat and long for example .

How about an image?

--
where do you call your procedure?

--

Also, it looks like you inverted the code for the x and y values in the atan2 block.   So, I am not sure how you got this to point in the 'right direction.

--
when y call the procedure then the phone does not response any longer

--
Y have used this 


 atan2( sin(long2-long1)*cos(lat2),cos(lat1)*sin(lat2) â sin(lat1)*cos(lat2)*cos(long2-long1))

cos(lat1)*sin(lat2) â sin(lat1)*cos(lat2)*cos(long2-long1)
is this wrong?

--
well, without calling the procedure everything you did was useless?
you might want to fix the mentioned errors and provide another screenshot?

--
No, not wrong, just misplaced.

again, look at the example in classic AI and compare it with the x blocks in your code and the x blocks in the example.

As Taifun said,   you MUST call the procedure.    Possibly it was not working because of coding errors.   Fix things, try again.   :)

--
nou y have called tehe procedure en switched everything to place.

Y am not shure if y have made variable like it should be.




--
I suspect that I should use. a clock

--
The error statement says that where you multiply 4.899   (your longitude perhaps)   x    a value that is an empty string     implies that  targetlatitude.text   or targetlongitude.text    contains no value.

Where do you assign the values for targetlatitude.text  and targetlongitude.text?       It appears, among many issues, this is the current problem Tony.   So I ask again, where are the blocks where you put the values from a list or listpicker into the latitude/longitude text boxes?  The latest problem is probably there.

--
No, you do not need a clock.

--
Y attached a printscreen of the label.


--
Thanks Tony.   It appears you have hard-coded the latitude in   targetlat and it is 52,379189 .   That appears to be OK.

What value did you hard-code in the longitude in targetlong label?   What I am trying to establish is if the targetlong label is empty or if it has a numerical value.   I do not need an image,
just the value. Thanks.

If you have a value in targetlong, then there is another issue that may involve the trig functions.

--
Y finally now what the problem was.
Thank u both Steve and Taifun.

It will not do any calculation because of the comma it uses. I changed it using "change all text" from "," to "."

it gives an error in the first instance because there is no value. The value needs to be first located by GPS before making the calculation. 
Here I have some more to come up with a solution, because it's annoying every time an error. 

I am very happy because this is my first app ever.

--
OK Tony.    I would have suspected the comma decimal versus the North American period decimal separator would have sorted themselves out.  Evidently not.

Very good detective work.  So changing the decimal value input from a , to a . fixed it?

And yes, the GPS first has to have a 'fix' before it will provide a value for currentlatitude1.text and currentlongitude1.text .      The coding could be fixed to check for a value in both of those before doing the calculation or you could set each to a dummy value when you initialize the screen.    In the Screen1.Initialize block, put the following:
set currentlatitude1.text to 1      
set currentlongitude1.text to 1          or another value close to your latitude/longitude  and it should help to fix the issue regarding waiting for the GPS to get the fix.  The example code, evidently does not tell users to do that I assume.    However, it is good error avoidance coding.

--
Y used a dummy as you told and works great.

y stil do not have the right calculation.
The values that come out are not good. 

this sould have been different values.
Now y am looking if y can find an easier way to calculate.

--
Regarding  Y used a dummy as you told and works great.
I assume this means you are no longer getting the error message.

Regarding  y still do not have the right calculation.
The values that come out are not good. 

Could you show an example?  What values are not good?  The bearing?   The way the arrow points or what?


this sould have been different values.
Regarding:  Now y am looking if y can find an easier way to calculate.

Easier, well, the formulas you have are about the easiest (at the expense of not being accurate over long distances).  They are simple trig assuming a flat Earth.

Tony, earlier, I mentioned the haversine algorithm:  http://www.movable-type.co.uk/scripts/latlong.html

Here is another discussion of how to calculate bearing:  http://mathforum.org/library/drmath/view/55417.html

Neither of the above examples use a compass rose or arrow, they just calculate the bearing in degrees.  Also, they are not AI2 blocks....you have to write the blocks yourself.

What answers do you get and what answers do you expect?

--
Y am taking a break from it.

Next week i will get into it again.

--
you can now find my solution here https://puravidaapps.com/snippets.php#2bearing

--
Thank y so much.
Y am very thankfull.

Y will try this tomorrow after work.

--
yes works perfect

--

댓글 없음:

댓글 쓰기