How do I efficiently get a Google location's CID from its place ID?

I am developing an application and I need to find a lot of locations' Google CIDs. The Places Text-search API is what best suits my needs, allowing me to find up to 20 locations at a time, which is plenty for what I need. However, this API doesn't return the CIDs. It does return a property called Place ID.

After researching this problem for a few hours I found several ways of doing it manually, or finding the Place ID from the CID. The first doesn't work as it's too much effort for when I need to search hundreds of locations every day. And the second is the reverse of what I need.

Is there an API/parameter/property I am missing that would allow me to find a location's CID, using it's Place ID?

1 answer

  • answered 2020-08-06 19:48 Sam Hill

    Here's something you may want to try. If you use the place details API:

    https://maps.googleapis.com/maps/api/place/details/json?key=KEY&place_id=PLACEID
    

    It will return a long list of details about that place. One of these is url and it contains the CID. You can return only the URL and save some money by adding &fields=url to the end of the request:

    https://maps.googleapis.com/maps/api/place/details/json?key=KEY&place_id=PLACEID&fields=url
    

    Unfortunately this does require more API calls, but it shouldn't be too much of an issue.