我的应用程序出现错误:
无法检测到当前的 Activity。确保您已在 Activity 或 Application 类中调用了 Init。
我使用模拟器 Genymotion。 GPS 已启用
public async Task btnAdd_Click()
{
try
{
var request = new GeolocationRequest(GeolocationAccuracy.Medium);
var location = await Geolocation.GetLocationAsync(request);
if (location != null)
{
string note = "GPS: Latitude-" + location.Latitude + " Longitude-" + location.Longitude;
}
}
catch (Exception ex)
{
// Unable to get location
}
}
就像错误状态一样,您是否添加了这一行:
Xamarin.Essentials.Platform.Init(this, bundle);
In your MainActivity.cs
in the OnCreate
method?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)