Obtaining the direction from the map componen

Hello,

Is there a way to get the direction of movement (arrow) from the map component? It is nicely shown on the component but I'd like to obtain its numerical value.

Thanks in advance.

ShowCompass specifies whether to display a compass overlay on the Map. The compass will rotate based on the device’s orientation if a digital compass is present in hardware. This is discussed in Map.

There is not any way to display the azimuth shown by that compass . The compass shows direction but does not provide a method for the user to display a numerical value.

However, you can calculate the direction of travel using Blocks.

The link shows one way to calculate a bearing using a Marker and the Map component and the LocationSensor. 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.

Alternatively, you can use the extension AdvancedLocationSensor v1.2 by Niclas Gins to obtain a bearing directly.
AdvancedLocationSensor
The ability to report the bearing of the direction of travel is not part of the standard LocationSensor or the Map component. You need to use a LocationSensor extension or the code shown in the link.

Did this answer your question Sito?

Thanks a lot for your help, Steve. I will try some of those.
Regards
Sito

Good luck.

A bit of caution; the Block solution to calculate a bearing from one location to another in the link I provided earlier is not very robust. It works but does not work properly for all situations. The following Block solution is more robust and should always calculate correctly. Sorry, only tested for locations west of the prime meridian and northern hemisphere. Other locations might require adjustments to the code.

The simple solution using Markers should work everywhere!

Hi Steve,

Indeed, I've got my own code for calculating the direction from two consecutive locations. But I have the feeling that what the map component does is better. Maybe it has to do with the way in which I "sample" location points for calculating directions... It looks like the map component has a better heuristic for that (?). So I'll try that "advanced location sensor" you suggested as, for sure, it solved that in a much better way than mine.

Thanks again for your help.