How to record vehicle tracking in xamarin forms and show on google map

amritpal singh 21 Reputation points
2021-04-09T17:02:56.76+00:00

Hi

I want to develop an app in xamarin forms to record a vehicle tracking and show them using google map. any idea or any sample app do this job. please sugest me that xamarin is good for to develop sucha app? the tracking must be run as long running task.

Thanks

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,378 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JessieZhang-MSFT 7,711 Reputation points Microsoft Vendor
    2021-04-12T07:46:27.25+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    You can use Xamarin.Essentials: Geolocation or the Geolocator Plugin to achieve this function.

    For Xamarin.Essentials: Geolocation, you can query the current device's location coordinates by using method GetLocationAsync :

       CancellationTokenSource cts;  
      
    async Task GetCurrentLocation()  
    {  
        try  
        {  
            var request = new GeolocationRequest(GeolocationAccuracy.Medium, TimeSpan.FromSeconds(10));  
            cts = new CancellationTokenSource();  
            var location = await Geolocation.GetLocationAsync(request, cts.Token);  
      
            if (location != null)  
            {  
                Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");  
            }  
        }  
        catch (FeatureNotSupportedException fnsEx)  
        {  
            // Handle not supported on device exception  
        }  
        catch (FeatureNotEnabledException fneEx)  
        {  
            // Handle not enabled on device exception  
        }  
        catch (PermissionException pEx)  
        {  
            // Handle permission exception  
        }  
        catch (Exception ex)  
        {  
            // Unable to get location  
        }  
    }  
    
    protected override void OnDisappearing()  
    {  
        if (cts != null && !cts.IsCancellationRequested)  
            cts.Cancel();  
        base.OnDisappearing();  
    }  
    

    You can save Latitude and Altitude coordinate after 10 sec or 20 sec in a form of csv values in text file.

    And there are some tutorials about this, you can find these tutorials by enter keywords Finding Your Way with the Xamarin.Essentials Geolocation API and Xamarin Forms Google Maps Tracking Path in your browser.

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.