Reputation: 463
I want to access the mean sea level of an location using .NET MAUI with native Android calls:
Permissions.RequestAsync<Permissions.LocationWhenInUse>().Wait();
var locationManager = (LocationManager)MauiApplication.Current
.GetSystemService(Context.LocationService)!;
var location = locationManager.GetLastKnownLocation(LocationManager.GpsProvider);
var mslLocation = location.MslAltitudeMeters;
But this results in an Java.Lang.IllegalStateException: 'The Mean Sea Level altitude of this location is not set.'
.
I also tried using RequestLocationUpdates:
locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 100L, 0f, new LocationListener());
class LocationListener : Java.Lang.Object, ILocationListener
{
public void OnLocationChanged(global::Android.Locations.Location location)
{
var mslLocation = location.MslAltitudeMeters;
}
public void OnProviderDisabled(string provider)
{
}
public void OnProviderEnabled(string provider)
{
}
public void OnStatusChanged(string? provider, [GeneratedEnum] Availability status, Bundle? extras)
{
}
}
I have the following AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>
In both cases msl location is not available. Am i missing something? Are there any permissions required? I could not find anything in the official documentation for the Location class in Java
Upvotes: 0
Views: 81