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

2

27

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?

enter image description here

Hagerty answered 6/9, 2015 at 23:28 Comment(6)
Google doesn't provide this information from their API...There is dew suggestion over here #16177735 you can try, but they wouldn't give you "Home" or "Work" addressHotspur
I've seen that question. I understand there's no .getHomeLocation() and .getWorkLocation() anywhere and that's OK. But then Google Inbox does get those values from somewhere somehow. There must be a way.Hagerty
@KrzysztofKozmic it is possible that Inbox uses a private API to access that informationArmageddon
or that googleinbox does a call from "serverside" and the call is limited to "googleIPs"Spider
The list somehow makes its way to my phone...Hagerty
@Heyyou Ultimate goal is to have the users pick a location, which 99% of the time would be their home or work so being able to have it right there in the list makes most sense.Hagerty
S
13

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

Syllabogram answered 16/9, 2015 at 7:15 Comment(2)
Thanks, that's some interesting pointers and avenues for investigation. I'll try experimenting with it over the weekend. For now I'll hold off accepting the answer in case someone provides a working POC sample.Hagerty
Update: Google Now maintains it's own Home/Work locations that you can set manually, but that are automatically deduced based on other available information, first and foremost your Google Maps routes to/from locations during typical work hours, and which location you sleep at every night (though the actual logic behind what constitutes "sleeping at" is assumed by me).Syllabogram
H
1

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.

Hypoploid answered 12/9, 2015 at 12:0 Comment(1)
UserAddress is always null. Trying on real device with valid userWichita

© 2022 - 2024 — McMap. All rights reserved.