如何从Google+ API获取Android设备的当前位置?

3

我需要从Google+ API获取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();

我成功获取了所有数据,但是位置为空。

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


你在清单文件(manifest)中添加了 ACCESS_COARSE_LOCATION 和 ACCESS_FINE_LOCATION 权限吗? - Ryan Byrne
不,我没有。我现在会尝试。 - Zookey
我添加了这些权限,但它又变成了null。 - Zookey
@Zookey:这个问题解决了吗?你能获取到没有设置封面照片的用户的封面照片 URL 吗?我有一个奇怪的问题:http://stackoverflow.com/questions/24995808/google-plus-cover-photo-in-android - TheDevMan
1个回答

1

嗯,我的同事正在为他的iPhone应用程序获取currentLocation。这个问题只与Android有关吗? - Zookey
据我所知,根据问题描述,可能存在未记录的作用域使其可行。也许你的同事正在使用额外的作用域? - abraham
他使用PROFILE作用域,正如你可以从上面的代码看到我也在使用它。 - Zookey

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接