FusedLocationProviderClient - 找不到类型或命名空间(错误)

FusedLocationProviderClient - type or namespace could not be found (error)

很抱歉,如果这真的很简单(也无法在 Marshmallow 模拟器上安装 google 播放服务,并且有点紧张!)。

我的目标是在 Visual Studio 2017 (15.6.3) 的 Xamarin Android C# 项目中获取 GPS 数据。

我正在关注 Xamarin 位置服务演练 (https://docs.microsoft.com/en-gb/xamarin/android/platform/maps-and-location/location#using-the-fused-location-provider) 和源代码示例。我已经尝试分别针对 Android 6.0(我的首选)和 7.1 以及 MonoAndroid6 和 MonoAndroid71。

我确实已经为 Xamarin.GooglePlayService.Location、.Maps 和所需的 'base' 库(.Base、.Basement 和 .Tasks)安装了 NuGet 包 - 版本 32.961.0 和 42.1021.1 (目标依赖者)。

下面的代码告诉我"The type or namespace name 'FusedLocationProviderClient' could not be found (are you missing a using directive or an assembly reference?"

private FusedLocationProviderClient fusedLocationProviderClient;

我已经使用对象浏览器来浏览这些库,甚至没有看到 FusedLocationProviderClient(只是 FusedLocationProviderApi - 我也在 SO 上读到它已被弃用...)。

我应该使用 'older' 定位服务 API 来定位 6.0,还是我遗漏了其他东西?

非常感谢。

一个Xamarin.Android项目涉及三个API级别,一个是Xamarin特定的,即Target Framework不是 与在应用程序清单中设置 targetSdkVersionTarget Android Version 混淆。

Target Framework – Specifies which framework to use in building your application. This API level is used at compile time by Xamarin.Android.

Minimum Android Version – Specifies the oldest Android version that you want your app to support. This API level is used at run time by Android.

Target Android Version – Specifies the version of Android that your app is intended to run on. This API level is used at run time by Android.

将您的 Target Framework 设置为最新最好的(当前为 8.1),将 Target Android Version 设置为 6.0 并(重新)安装您的软件包。

理解 Android API 水平:https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/android-api-levels?tabs=vswin

只需添加 NuGet 包 Xamarin.GooglePlayServices.Location