Skip to first unread message

TonyMONANA

unread,
Jun 10, 2014, 7:15:19 PM6/10/14
to mitappinv...@googlegroups.com
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



MVG,
Tony

SteveJG

unread,
Jun 10, 2014, 7:48:47 PM6/10/14
to mitappinv...@googlegroups.com
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.

Good luck.
Regards,
Steve

Taifun

unread,
Jun 10, 2014, 8:34:51 PM6/10/14
to mitappinv...@googlegroups.com
you might be interested in this App Inventor Classic snippet https://groups.google.com/d/msg/programming-with-app-inventor/gW1Y0JGz-GI/qyLMqcL1NokJ
Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

Message has been deleted

TonyMONANA

unread,
Jun 13, 2014, 1:42:19 PM6/13/14
to mitappinv...@googlegroups.com
Hi. 

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
Bearing.jpg
azimuth.jpg
bearingpoint.png

SteveJG

unread,
Jun 13, 2014, 1:57:59 PM6/13/14
to
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.

Did that help?

Regards,
Steve







TonyMONANA

unread,
Jun 13, 2014, 2:16:07 PM6/13/14
to mitappinv...@googlegroups.com
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?

TonyMONANA

unread,
Jun 13, 2014, 2:29:57 PM6/13/14
to mitappinv...@googlegroups.com
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.


SteveJG

unread,
Jun 13, 2014, 3:19:04 PM6/13/14
to mitappinv...@googlegroups.com
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?

-- Steve



Taifun

unread,
Jun 13, 2014, 3:19:54 PM6/13/14
to mitappinv...@googlegroups.com
where do you call your procedure?
Taifun

SteveJG

unread,
Jun 13, 2014, 3:22:15 PM6/13/14
to
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.

TonyMONANA

unread,
Jun 13, 2014, 4:06:17 PM6/13/14
to mitappinv...@googlegroups.com
when y call the procedure then the phone does not response any longer

TonyMONANA

unread,
Jun 13, 2014, 4:09:24 PM6/13/14
to mitappinv...@googlegroups.com
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?

Taifun

unread,
Jun 13, 2014, 4:11:28 PM6/13/14
to mitappinv...@googlegroups.com
well, without calling the procedure everything you did was useless?
you might want to fix the mentioned errors and provide another screenshot?
Taifun

SteveJG

unread,
Jun 13, 2014, 4:23:46 PM6/13/14
to mitappinv...@googlegroups.com
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.   :)

Regards,
Steve

TonyMONANA

unread,
Jun 13, 2014, 5:10:13 PM6/13/14
to mitappinv...@googlegroups.com
nou y have called tehe procedure en switched everything to place.

Y am not shure if y have made variable like it should be.
blocks.png
Naamloos.png
2.png

TonyMONANA

unread,
Jun 13, 2014, 5:17:33 PM6/13/14
to mitappinv...@googlegroups.com
I suspect that I should use. a clock

SteveJG

unread,
Jun 13, 2014, 5:21:56 PM6/13/14
to mitappinv...@googlegroups.com
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.

Regards,
Steve

SteveJG

unread,
Jun 13, 2014, 5:22:40 PM6/13/14
to mitappinv...@googlegroups.com
No, you do not need a clock.

TonyMONANA

unread,
Jun 13, 2014, 5:47:50 PM6/13/14
to mitappinv...@googlegroups.com
Y attached a printscreen of the label.

Naamloos.png

SteveJG

unread,
Jun 13, 2014, 7:37:08 PM6/13/14
to mitappinv...@googlegroups.com
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.


TonyMONANA

unread,
Jun 13, 2014, 7:42:53 PM6/13/14
to mitappinv...@googlegroups.com
Y finally now what the problem was.
Thank u both Steve and Taifun.


It wil not do eny calculation because of the comma it uses. I changed it using "change al 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.

SteveJG

unread,
Jun 13, 2014, 7:49:28 PM6/13/14
to
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.
   

-- Steve

TonyMONANA

unread,
Jun 14, 2014, 8:58:11 AM6/14/14
to mitappinv...@googlegroups.com
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.

SteveJG

unread,
Jun 14, 2014, 11:46:40 AM6/14/14
to mitappinv...@googlegroups.com
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 stil 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?

Regards,
Steve





TonyMONANA

unread,
Jun 14, 2014, 12:04:19 PM6/14/14
to mitappinv...@googlegroups.com
Y am taking a break from it.

Next week i wil get into it again.


Taifun

unread,
Jun 14, 2014, 5:44:11 PM6/14/14
to mitappinv...@googlegroups.com
you can now find my solution here https://puravidaapps.com/snippets.php#2bearing
Taifun


TonyMONANA

unread,
Jun 14, 2014, 7:08:43 PM6/14/14
to mitappinv...@googlegroups.com
Thank y so mutch.
Y am very thankfull.

Y will try this tommorrow after work.


TonyMONANA

unread,
Jun 15, 2014, 10:59:05 AM6/15/14
to mitappinv...@googlegroups.com
yes works perfect

Peter

unread,
Jul 24, 2019, 5:45:04 AM7/24/19
to MIT App Inventor Forum
Hi guys, Sadly this doesn't work for me. It's a great base example for the start of what I am trying to do but can't get it to work.
The bearing stays the same at 180 no matter where i place the Long / Lat. Not sure where to go from here or where I am wrong? I read something about changing the + to - or vice versa but in Australia so don't think this changes for me I downloaded direct from your snippet link above. I have only changed the long / Lat.
blocks.png

SteveJG

unread,
Jul 24, 2019, 9:08:43 AM7/24/19
to mitappinv...@googlegroups.com
@ Peter.... the behavior you see might be just a matter of how the Orientation sensor works.  Please walk away from you computer screen and other magnetic objects when you test. The Orientation sensor is affected by magnetic fields.


Here is a way to use the MIT Map Component to do something similar  https://groups.google.com/forum/#!searchin/mitappinventortest/bearing%7Csort:date/mitappinventortest/S5hZz3SegDE/gdue-PEuAwAJ  

if you use the compass that is part of the Map Component.   It might help to build something similar to Taifun's example... but it does not use the OrientationSensor..

A long time ago, I discovered Taifun's example does not work in all situations ,
you might try the following algorithm

bearing.PNG


Does either of these work for you?

Regards,
Steve

Peter

unread,
Jul 27, 2019, 4:07:54 AM7/27/19
to MIT App Inventor Forum
Thanks so much Steve. I am by no shot a programmer (haven't done anything for almost 20 years) heads probably not screwed on right either.... and greatly appreciate your reply. Some things are coming back slowly :) It took me a while as the bearing procedure block that you used I couldn't find, however managed to locate from another project. I did a lot of playing with several suggestions and have it working now using some markers on a map which I used to move around my neighbourhood and point to (I was skeptical after the other failed attempts and nearly ditched it but finally manged it). I figure I am just going to chip away at  small bits of my large project and finally will get the job done. 
...Now I am trying to piece several smaller processes together 

Greatly appreciated and you now have my daughter interested in making projects as well :) 
blocks (1).png
Reply all
Reply to author
Forward
0 new messages