FusedLocationProviderClient - type or namespace co

2019-07-31 03:56发布

So sorry if this is really simple (also failing to install google play services on Marshmallow emulator, and getting a tad wound up!).

I am aiming to get GPS data in a Xamarin Android C# project on Visual Studio 2017 (15.6.3).

I am following the Xamarin Location Services walkthrough (https://docs.microsoft.com/en-gb/xamarin/android/platform/maps-and-location/location#using-the-fused-location-provider) and source code examples. I have tried targeting Android 6.0 (my preferred) and also 7.1 and MonoAndroid6 and MonoAndroid71, respectively.

I have definitely installed the NuGet packages for Xamarin.GooglePlayService.Location, .Maps and the required 'base' libraries (.Base, .Basement and .Tasks) - versions 32.961.0 and 42.1021.1 (target dependant).

The following code tells me "The type or namespace name 'FusedLocationProviderClient' could not be found (are you missing a using directive or an assembly reference?"

private FusedLocationProviderClient fusedLocationProviderClient;

I have used Object Browser to explore the libraries, and do not even see FusedLocationProviderClient (just FusedLocationProviderApi - which I also read on SO is deprecated...).

Should I be using the 'older' Location Service APIs to target 6.0, or am I missing something else?

Many thanks.

2条回答
爷的心禁止访问
2楼-- · 2019-07-31 04:17

Just add the NuGet package Xamarin.GooglePlayServices.Location

查看更多
祖国的老花朵
3楼-- · 2019-07-31 04:18

There are three APIs levels involved in a Xamarin.Android project, one is Xamarin specific, that is the one Target Framework, not to be confused with the Target Android Version that sets the targetSdkVersion in the app's Manifest.

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.

Set your Target Framework to the latest and greatest (currently 8.1), the Target Android Version to 6.0 and (re-)install your packages.

Understanding Android API Levels : https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/android-api-levels?tabs=vswin

查看更多
登录 后发表回答