Question

By fetching a Google place one gets the following results back: https://developers.google.com/places/documentation/details

Since I later need to update a saved place in my database it would be nice if Google Places would offer an unique and static identifier. I thought I might could use "id" or "reference" for that, unfortunately they are not static and can and do change all the time:

id contains a unique stable identifier denoting this place. This identifier may not be used to retrieve information about this place, but can be used to consolidate data about this Place, and to verify the identity of a Place across separate searches. As ids can occasionally change, it's recommended that the stored id for a Place be compared with the id returned in later Details requests for the same Place, and updated if necessary.

So ID cannot be used if I understand the last sentence correctly.

reference contains a token that can be used to query the Details service in future. This token may differ from the reference used in the request to the Details service. It is recommended that stored references for Places be regularly updated. Although this token uniquely identifies the Place, the converse is not true: a Place may have many valid reference tokens.

Saving the reference key would allow one to always find the place, but the reference key on a query is never the same. It changes with every query.

I'm really not sure how to solve this. Any ideas?

Was it helpful?

Solution

In your case I would cache both ID and Reference in your datastore, as ID can be used to de-duplicate responses from the web service, and References can be used to get additional details such as photos and the like. When IDs shift, you'll want to revisit the data and confirm whether the new place is the same as the old one by your business rules.

I need to point out that you can only cache data from the Places API for performance reasons, and you shouldn't be storing the data permanently, as per our Terms of Service.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top