Using map component (to calculate a bearing)

42 views
Skip to first unread message

michael judkovsky

unread,
May 14, 2019, 1:29:57 AM5/14/19
to mitappinv...@googlegroups.com
Hello
When using the Map ShowUser property the arrow symbol on the screen rotates and points to the direction of motion. It means that the Bearing angle is calculated somewhere in the background.Is it possible to obtain that angle?
Thanks!!!
Mike

SteveJG

unread,
May 14, 2019, 9:45:53 AM5/14/19
to mitappinv...@googlegroups.com
Yes and no.  You cannot determine a bearing directly.  To get a bearing, place a Marker component and use either the Marker1.BearingToFeature or Marker1.BearingToPoint Blocks along with appropriate coding.  The component will not provide a current bearing.  There is no provision for this.   

I think you can use the Marker1.BearingToPoint by using the UserLatitude and UserLongitude blocks.   Experiment.

See also your previous Forum post that contains an alternative way to calculate a bearing using only Blocks ( https://groups.google.com/forum/#!searchin/mitappinventortest/bearing%7Csort:date/mitappinventortest/sUUjS5wKR9A/p7B7jgMwAgAJ ).

Regards,
Steve

michael judkovsky

unread,
May 15, 2019, 8:00:12 AM5/15/19
to MIT App Inventor Forum
Thanks a lot Steve
I will try to implement your suggestion!

SteveJG

unread,
May 15, 2019, 10:04:37 AM5/15/19
to MIT App Inventor Forum
Here is one way to calculate a bearing using a Marker and the Map component.   Two points are needed to determine a bearing.  The bearing shows the direction of travel from a previous location to your actual location.  When you ask for the bearing, that is what is provided.    The calculation works by saving a 'previous location' and calculating the direction of movement from the previous location to the current location.


The attached image may help design your Blocks Mike.  Let me know if it works for you.  I tested it on an Android 8.1 tablet and it seems to work correctly.  You might include code to ignore the first bearing (which will calculate a bearing from the equator to your current location.  The second bearing will calculate a bearing from your previous location to current location which might result in nonsense since those two locations will be identical or very close together if your device is not moving.



Regards,
Steve
bearingfromMapcomponent.PNG
Reply all
Reply to author
Forward
0 new messages