How to get GoogleApiClient in Xamarin?

会有一股神秘感。 提交于 2020-01-14 07:21:26

问题


I want to implement something like this in my Android application that I'm developing in Xamarin but can not find a namespace in which the GoogleApiClient is. Can anybody help?


回答1:


GoogleApiClient is in the Android.Gms.Common.Apis namespace.

That namespace is in the "Xamarin.GooglePlayServices.Basement" assembly, but you do not install that directly.

So, assuming you are trying to access that in doing some Android Location/Map development, install this nuget:

Xamarin Google Play Services - Location

Xamarin.Android Bindings for Google Play Services - Location

One of the unique features of mobile applications is location awareness. Mobile users take their devices with them everywhere, and adding location awareness to your app offers users a more contextual experience. The location APIs available in Google Play services facilitate adding location awareness to your app with automated location tracking, geofencing, and activity recognition.

To install Xamarin Google Play Services - Location, run the following command in the Package Manager Console

PM> Install-Package Xamarin.GooglePlayServices.Location

Using clause:

using Android.Gms.Common.Apis;

Code:

var foo = GoogleApiClient ();



回答2:


In addition to RobertN answer, it seems there were some naming/namespace changes in 27.0.0.0.

So here's an example that might help:

GoogleApiClient api = new GoogleApiClient.Builder (Application.Context, this, this)
    .AddApi (Android.Gms.Location.LocationServices.API)
    .Build ();

In the above code this means that the below interfaces are implemented:

  • Android.Gms.Common.Apis.GoogleApiClient.IConnectionCallbacks
  • Android.Gms.Common.Apis.GoogleApiClient.IOnConnectionFailedListener



回答3:


It should be noted that the command "Install-Package Xamarin.GooglePlayServices.Location" also works for updating the Xamarin.GooglePlayServices. It will always fail if you try to use the UI to update the components.



来源:https://stackoverflow.com/questions/33391731/how-to-get-googleapiclient-in-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!