Xamarin Forms Maps - Set bearing (using compass)

AbhiNilAbhiNil CAMember ✭✭✭

Hey Guys ,

I'm building a map centric app and having a small issue .

I am displaying my map and getting current location . I can see the blue dot on the map and the directional arrow appears sometimes .

However i can't find any way to set the bearing . (or set the arrow to the direction the phone is pointing at)

Such as in google maps app , when you move the phone around - you can see the user position showing a directional fog towards where the phone is pointing .

I am using the compass plugin and getting the compass reading between 0-360 , however i'm not sure how to add that to my map + user location to make the arrow point in that direction.

Any ideas how to proceed ?

Tagged:

Answers

  • hadihashemhadihashem Member ✭✭

    Hello
    Did you solve this issue?

  • Amar_BaitAmar_Bait DZMember ✭✭✭✭✭
    edited July 9

    This post is 3 years old and dead. Please open a new question in the future.

    Install and setup Xamarin.Essentials correctly.

    Your page:

    <Grid>
        <Map HorizontalOptions="Fill" VerticalOptions="Fill" />
        <Image x:Name="PointerImage" Source="pointer.png" HorizontalOptions="Center" VerticalOptions="Center"  />
    </Grid>
    

    pointer.png image:

    Your page code-behind:

    using Xamarin.Essentials;
    
    public class Page : ContentPage
    {
        public Page()
        {
            InitializeComponent();
            Compass.ReadingChanged += (s, e) => PointerImage.RotateTo(e.Reading.HeadingMagneticNorth, 200);
            Compass.Start(SensorSpeed.UI, applyLowPassFilter: true);
        }
    }
    
  • hadihashemhadihashem Member ✭✭

    Hello and thank you for your help
    I followed the instruction but I get an exception at the end

  • Amar_BaitAmar_Bait DZMember ✭✭✭✭✭
    edited July 9

    Your device doesn't support compass then. Find one that supports it.

    try
    {
        Compass.Start(SensorSpeed.UI, applyLowPassFilter: true);
    }
    catch (FeatureNotSupportedException fnsEx)
    {
        // Feature not supported on device...
        // Maybe display error message...
    }
    
Sign In or Register to comment.