Looking at the sample, it appears the problem you're having is that you're not requesting the ACCESS_FINE_LOCATION permission. First, you need to have this permission included in your manifest. I'm guessing you've already done that in your production app and just overlooked it in your little reproducer app. The part that's easier to miss is that, on Android 6.0 (API 23) and up, you also need to explicitly include logic in your app to request this permission at run-time. Resources on that include:
It's definitely NOT intuitive to add that logic, however (at least I don't find it so), so I've taken the liberty of updating your sample with the necessary code and have attached that. The relevant pieces of code are:
Implement ActivityCompat.IOnRequestPermissionsCallback in your MainActivity, checking that the response is coming from a location permissions check, and raising a notification for your fragment to handle:
public void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults)
{
if (requestCode == LocationPermissionsRequestCode && grantResults.Length == 1)
{
LocationPermissionResponseReceived?.Invoke(this, grantResults[0]);
}
}
internal static int LocationPermissionsRequestCode = 32987;
internal event EventHandler<Android.Content.PM.Permission> LocationPermissionResponseReceived;
In your fragment, verify that location permission has been granted before enabling location display. If it hasn't been, request it:
if (ContextCompat.CheckSelfPermission(this.Context, Android.Manifest.Permission.AccessFineLocation) == Android.Content.PM.Permission.Granted)
{
this.mapView.LocationDisplay.IsEnabled = true;
}
else
{
var mainActivity = (MainActivity)this.Activity;
EventHandler<Android.Content.PM.Permission> locationPermissionResponseReceivedHandler = null;
locationPermissionResponseReceivedHandler = (o, e) =>
{
mainActivity.LocationPermissionResponseReceived -= locationPermissionResponseReceivedHandler;
if (e == Android.Content.PM.Permission.Granted)
{
this.mapView.LocationDisplay.IsEnabled = true;
}
};
mainActivity.LocationPermissionResponseReceived += locationPermissionResponseReceivedHandler;
Android.Support.V4.App.ActivityCompat.RequestPermissions(
this.Activity,
new string[] { Android.Manifest.Permission.AccessFineLocation },
MainActivity.LocationPermissionsRequestCode
);
}
Hope this helps!