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

Matt picture Matt · Apr 14, 2016 · Viewed 33.1k times · Source

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?

Answer

Giorgi picture Giorgi · Apr 14, 2016

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