I want to get my gps coordinates on a Xamarin CrossPlatform app, but I have a problem.
I have this code:
public MapPage()
{
SearchPosition();
map = new Map
{
IsShowingUser = true,
HeightRequest = 100,
WidthRequest = 960,
VerticalOptions = LayoutOptions.FillAndExpand
};
map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(position.Latitude, position.Longitude), Distance.FromMiles(0.3)));
...
...
}
private async void SearchPosition()
{
position = await getPosition();
}
async Task<Plugin.Geolocator.Abstractions.Position> getPosition()
{
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
Plugin.Geolocator.Abstractions.Position position = await locator.GetPositionAsync(TimeSpan.FromSeconds(5));
return position;
}
All I want is to wait for the gps coordinates, but it continues and goes to "MoveToRegien" before I have the gps coordinates. I don't understand why, can anyone help me? Thanks!