Get user's home, work and starred locations like Google Inbox does

你。 提交于 2019-11-30 10:59:39

问题


When in Google Inbox you go to snooze a message and select 'Pick place' it shows a list with your home and work address (from Google Now) populated as well as starred locations from your Google Maps profile. Other Google apps, like Keep also provide similar functionality.

I would like to implement this in my app but couldn't find the right API that exposes that information. Is that something that Google doesn't expose to 3rd parties (I guess there's room for abuse there)?

If not, how can this be implemented? What API has the data?


回答1:


Google Now utilizes analytics on your location data (on any and all devices signed into Google + location services enabled in your Google Account settings) to determine your home and work locations, unless you specifically set them.

The storage / retrieval of this data is not explicitly referenced anywhere that I have found in official Google documentation, but the schema in Google Now for this data is available here: Google Schema - Person

For any given person entity, a homeLocation and workLocation property exists with that data.

Alternatively (or in addition to), using Google's Plus Platform / Google Identity Platform, if you have an authenticated user, you can make an API call as described here (with examples) to get any of the specified fields for the current user (including currentLocation, organizations (including work) with addresses, if the user provided them).

A previous SO question that references using oAuth and raw Google Maps feed urls to pull the data exists, but the accepted answer is somewhat unclear and when I followed the links and attempted authenticated to test it out, I received 404 errors from all of them: Access locations in My Places of a particular account through Google Maps API

Also as in a Google Product Forums post here several years ago, a previous version of the Google Maps Data API allowed access to My Places, which is quintessentially exactly what you need, but it was deprecated and removed in 2013.

Finally, and this is the best approach in my opinion, and may be what Google uses (if it isn't declared to be Google Now), which is the Google Contacts API. A user exists in their own contact list, and the extensive API for Google Contacts allows you to get/set addresses with standard labels such as home or work for the user.

This is all detailed here: Google Contact Services - App Scripts




回答2:


Here is API for getting user's addresses

https://developers.google.com/android/reference/com/google/android/gms/identity/intents/Address

mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addApi(Address.API, new Address.AddressOptions())
        .build();
mGoogleApiClient.connect();
...
Address.requestUserAddress(mGoogleApiClient, UserAddressRequest.newBuilder().build(), REQUEST_CODE);


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    ...
    UserAddress address = UserAddress.fromIntent(data);
}

In dependencies

compile 'com.google.android.gms:play-services-identity:7.8.0'

There is no Home or Work addresses here, and I don't understand what kind of addresses it uses. But it seems that all user's addresses should be here.



来源:https://stackoverflow.com/questions/32429292/get-users-home-work-and-starred-locations-like-google-inbox-does

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