We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

retrieve current location programatically

Thread ID:

Created:

Updated:

Platform:

Replies:

147856 Sep 25,2019 09:43 PM UTC Sep 26,2019 11:12 AM UTC Xamarin.Forms 1
loading
Tags: SfMaps
maryam
Asked On September 25, 2019 09:43 PM UTC

I'm using the sfMap and I need to find usre current location and allow to zoom on the map.
Is there any way to retrieve location (programatically ) on SfMaps?

thanks.



Bharathiraja K [Syncfusion]
Replied On September 26, 2019 11:12 AM UTC

Hi Maryam, 
 
Greetings from Syncfusion. To find out the Current Geo location, we have to refer Xamarin.Essential package. After getting GeoCoordinate  location, we need to update this value to map markers to pin on the Maps. Please refer the below code snippet to get the GeoCoordinate points of current location. 
 
[C#]: 
private async void AddMarkerInCurrentLocation()
        {
            try
            {
                // To get the current location
                var location = await Geolocation.GetLastKnownLocationAsync();
               
                // Add the marker on the current location
                if (location != null)
                {
                    CustomMarker marker = new CustomMarker();
                    marker.Latitude = location.Latitude.ToString();
                    marker.Longitude = location.Longitude.ToString();
                    layer.Markers.Add(marker);
                }
            }
            catch (Exception ex)
            {
                // Handle not supported on device exception
                await Application.Current.MainPage.DisplayAlert("Alert", ex.Message, "Ok");
            }
        }
 
 
 
Please refer the below help document for adding Markers on Map.  
 
 
We have prepared a sample based on your requirement and it can be downloaded from the below link. 
 
 
Regards, 
Bharathi.  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon