Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current location or move to current location in Xamarin.Forms.Map

Tags:

Since the Map already shows the user location (with IsShowingUser) I just want to zoom to this location. Is this easily possible or do I need to get the location on every platform, since I don't find any GeoLocation object. Only the GeoCoder... Is this not a common usecase to zoom to users position?

like image 487
Matt Avatar asked Apr 14 '16 17:04

Matt


People also ask

What is xamarin essentials?

Xamarin. Essentials provides a single cross-platform API that works with any iOS, Android, or UWP application that can be accessed from shared code no matter how the user interface is created. See the platform & feature support guide for more information on supported operating systems.


1 Answers

You will need to call MoveToRegion method with the position you are interested in.

You can use Geolocator Plugin for Xamarin to get the location in PCL project:

var locator = CrossGeolocator.Current; var position = await locator.GetPositionAsync(10000); map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(position.Latitude, position. Longitude),                                               Distance.FromMiles(1))); 

Updated: Xamarin Forms now includes by default Xamarin.Essentials: Geolocation

like image 94
Giorgi Avatar answered Oct 15 '22 04:10

Giorgi