- Home
- Forum
- Xamarin.Forms
- retrieve current location programatically
retrieve current location programatically
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.
SIGN IN To post a reply.
3 Replies
BK
Bharathiraja K
Syncfusion Team
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.
Sample: http://www.syncfusion.com/downloads/support/directtrac/233455/ze/Maps_SQL_Offline-1582804962
Regards,
Bharathi.
YE
Yemoku
March 2, 2021 08:35 AM UTC
Greetings,
Is this sample code/project still available? I am getting an error on the link.
Many thanks,
yemoku
SS
Sridevi Sivakumar
Syncfusion Team
March 3, 2021 08:01 AM UTC
Hi Yemoku,
We would like to inform you that the below KB document will assist you to show the current GPS location in SfMaps.
https://www.syncfusion.com/kb/11379/how-to-show-the-current-gps-location-in-xamarin-forms-maps-sfmaps
Let us know if you need any further assistance.
Regards,
Sridevi S.
We would like to inform you that the below KB document will assist you to show the current GPS location in SfMaps.
https://www.syncfusion.com/kb/11379/how-to-show-the-current-gps-location-in-xamarin-forms-maps-sfmaps
Let us know if you need any further assistance.
Regards,
Sridevi S.
SIGN IN To post a reply.
- 3 Replies
- 4 Participants
-
MA maryam
- Sep 25, 2019 09:43 PM UTC
- Mar 3, 2021 08:01 AM UTC