Now, we will create a new method for loading the data. This will be a three-step process. First, we will get the location of the user. Once we have this, we can fetch data related to that location. The final step is to prepare the data that the views can consume to create a user interface for the user.
To get the location of the user, we will use Xamarin.Essentials, which we installed earlier as a NuGet package, and the Geolocation class, which exposes methods that can fetch the location of the user. Perform the following steps:
- Create a new method called LoadData. Make it an asynchronous method that returns a Task.
- Use the GetLocationAsync method on the Geolocation class to get the location of the user.
- Pass the latitude and longitude from the result of the GetLocationAsync call and pass it to the GetForecast method on the object that implements IWeatherService using the following code:
public async Task LoadData()
{
var location...