this is my code:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
//Initialize buttons:
Button StartButton = FindViewById<Button>(Resource.Id.startbutton);
TextView txtTestGps = FindViewById<TextView>(Resource.Id.GpsTest);
ShowGpsCoordinates(StartButton, txtTestGps);
}
private async void ShowGpsCoordinates(Button StartButton, TextView txtTestGps)
{
await StartButton.Click += (sender, e) =>
{
double xy = await GiveGpsLocation();
txtTestGps.Text = xy;
};
}
private async Task<double> GiveGpsLocation()
{
double DoubleWithCoordinates = 0.0;
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
var position = await locator.GetPositionAsync(10000);
// Console.WriteLine("Position Status: {0}", position.Timestamp);
// Console.WriteLine("Position Latitude: {0}", position.Latitude);
// Console.WriteLine("Position Longitude: {0}", position.Longitude);
DoubleWithCoordinates = position.Latitude;
return DoubleWithCoordinates;
}
}
}
but the part with the startbutton.click wont work. I made everything async so that i can convert task to doubles. But now i get: "The Event View.Click can only appear on the left hand side of += or -="
But, as far as i know, it is on the left hand side. Anyway, I think the problem is the async method, because before everything worked just fine. Only that there was no way to convert Task to x. Thats why I made the methods by async. Can any of you guys help me with my problem?
Regards :)