如何在Xamarin中获得GoogleApiClient?

时间:2015-10-28 12:58:46

标签: android google-maps xamarin google-api

我想在我的Android应用程序中实现类似this的内容,我在Xamarin中开发但无法找到GoogleApiClient所在的命名空间。有人可以帮忙吗?

3 个答案:

答案 0 :(得分:11)

GoogleApiClient位于Android.Gms.Common.Apis命名空间中。

该命名空间位于“ Xamarin.GooglePlayServices.Basement ”程序集中,但您不能直接安装它。

因此,假设您在进行某些Android位置/地图开发时尝试访问它,请安装此nuget:

Xamarin Google Play Services - Location

  

适用于Google Play服务的Xamarin.Android绑定 - 位置

     

移动应用程序的一个独特功能是位置   意识。移动用户随身携带他们的设备,并且   向您的应用添加位置感知功能可为用户提供更多内容   经验。 Google Play服务中提供的位置API   通过自动化方式为您的应用添加位置感知功能   位置跟踪,地理围栏和活动识别。

     

要安装Xamarin Google Play服务 - 位置,请运行以下命令   包管理器控制台中的命令

PM> Install-Package Xamarin.GooglePlayServices.Location

使用条款:

using Android.Gms.Common.Apis;

<强>代码:

var foo = GoogleApiClient ();

答案 1 :(得分:4)

除了RobertN的回答,似乎还有一些naming/namespace changes in 27.0.0.0

所以这是一个可能有帮助的例子:

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

在上面的代码中,意味着实现了以下接口:

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

答案 2 :(得分:0)

应该注意的是命令&#34; Install-Package Xamarin.GooglePlayServices.Location&#34;也适用于更新Xamarin.GooglePlayServices。如果您尝试使用UI更新组件,它将始终失败。