xamarin 表单的地理定位器插件
Geolocator plugin for xamarin forms
我正在尝试使用 Xamarin 表单开发移动应用程序,此应用程序的一部分是获取用户的 GPS 位置。
但是当我 运行 应用程序时,我收到此异常消息
This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.
我试图找到解决方案,但没有任何用处。有什么建议吗?
我将此权限添加到 android 应用:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
代码
try
{
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 100;
var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(20), null, true);
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
// throw;
}
可能的解决方案
根据author's documentations, you need to install Current Activity Plugin for Xamarin.Android。并在您的 MainActivity.cs
.
中添加以下代码行
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
// some code
CrossCurrentActivity.Current.Init(this, bundle);
LoadApplication(new App());
}
因为您的演示项目是 运行 在 .Net 4.5 上,我无法试用。可以仔细阅读作者的文档,再试一下。
我的推荐
我查看了您正在使用的 Github 页面 GeolocatorPlugin。作者声明:
The time is now with Xamarin.Essentials, which offers over 30 cross-platform native APIs in a single optimized package. I worked on this new library with an amazing team of developers and I highly highly highly recommend you check it out
所以你应该改用 Xamarin.essentials 插件。这是 Microsoft 的 the documentation 如何使用该插件的 Geolocation。
我也回答过类似的问题,你可能需要参考
经过几次尝试后,我通过将 xamarin.Forms 更新为带有其余 nuget 包的最新版本解决了这个问题。
我正在尝试使用 Xamarin 表单开发移动应用程序,此应用程序的一部分是获取用户的 GPS 位置。
但是当我 运行 应用程序时,我收到此异常消息
This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.
我试图找到解决方案,但没有任何用处。有什么建议吗?
我将此权限添加到 android 应用:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
代码
try
{
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 100;
var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(20), null, true);
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
// throw;
}
可能的解决方案
根据author's documentations, you need to install Current Activity Plugin for Xamarin.Android。并在您的 MainActivity.cs
.
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
// some code
CrossCurrentActivity.Current.Init(this, bundle);
LoadApplication(new App());
}
因为您的演示项目是 运行 在 .Net 4.5 上,我无法试用。可以仔细阅读作者的文档,再试一下。
我的推荐
我查看了您正在使用的 Github 页面 GeolocatorPlugin。作者声明:
The time is now with Xamarin.Essentials, which offers over 30 cross-platform native APIs in a single optimized package. I worked on this new library with an amazing team of developers and I highly highly highly recommend you check it out
所以你应该改用 Xamarin.essentials 插件。这是 Microsoft 的 the documentation 如何使用该插件的 Geolocation。
我也回答过类似的问题,你可能需要参考
经过几次尝试后,我通过将 xamarin.Forms 更新为带有其余 nuget 包的最新版本解决了这个问题。