【问题标题】:How to get current location from Google+ API for Android?如何从适用于 Android 的 Google+ API 获取当前位置?
【发布时间】:2014-03-14 15:05:53
【问题描述】:

我需要从 Google+ API for Android 获取当前位置。

我已经在 Google API 控制台中完成了所有操作,并将我的应用与带有 SHA1 的客户端 ID 和包名称相关联。

我成功获取了关于用户名、头像、封面图片、电子邮件的几乎数据...

但我的位置有问题。我无法获取用户位置。

我使用这个范围:

mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this).addApi(Plus.API, null)
    .addScope(Plus.SCOPE_PLUS_PROFILE).build();

我使用此代码获取个人资料信息:

 String personName = currentPerson.getDisplayName();
            String userId = currentPerson.getId();
            String personPhotoUrl = currentPerson.getImage().getUrl();
            String personGooglePlusProfile = currentPerson.getUrl();
            String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
            String location = currentPerson.getCurrentLocation();
            String coverPhoto = currentPerson.getCover().getCoverPhoto().getUrl();

我成功获取了所有这些数据,但我得到了 null 作为位置。

有人知道如何解决这个问题吗?

【问题讨论】:

  • 您是否将 ACCESS_COARSE_LOCATION 和 ACCESS_FINE_LOCATION 添加到清单中?
  • 不,我没有。我会试试看的。
  • 我添加了这些权限,但它又是空的。
  • @Zookey:这个问题解决了吗?您是否获得了未设置封面照片的用户的封面照片 URL?我有一个奇怪的问题:stackoverflow.com/questions/24995808/…

标签: android google-api google-plus


【解决方案1】:

看起来currentLocation 的值不是currently available through the API

【讨论】:

  • 嗯,我的同事为他的 iPhone 应用程序获取了 currentLocation。此问题是否仅与 Android 相关?
  • 我不知道,根据问题,可能存在启用它的未记录范围。也许您的同事正在使用额外的示波器?
  • 他使用 PROFILE 范围,我也使用它,从上面的代码中可以看到。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-01
  • 2014-06-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多