Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From Google Maps CID to Place ID

I have a bunch of links to google maps in the form of https://maps.google.com/?cid=<identifier>.

How can you go from that CID to a Place ID that can be used with the Google Places API? Is there any API endpoint that you can use to convert these URLs into the new places?

like image 267
Nicolás Sanguinetti Avatar asked Nov 25 '17 21:11

Nicolás Sanguinetti


People also ask

What does CID mean in Google?

Your customer ID is a unique number used to identify your Google Ads account. You can also use this number to connect your account with other Google products, such as Google Analytics or Business Profile.


3 Answers

Got lucky and found an undocumented api. If you have the CID, you can call the api like https://maps.googleapis.com/maps/api/place/details/json?cid=${CID}&key=YOUR_API_KEY.

I just changed place_id=${the_end_val_i_needed} to cid=${CID} and in the json response is the place_id.

like image 59
j_walker_dev Avatar answered Sep 28 '22 04:09

j_walker_dev


You can use this API hidden parameter to get Place ID. Usage: https://maps.googleapis.com/maps/api/place/details/json?cid=YOUR_CID&key=YOUR_KEY

It returns a result contains formatted address, place_id, name of the address and GPS coordinater.

Please see my blog to see more detail: https://leonbbs.blogspot.com/2018/03/google-map-cid-to-placeid-or-get.html

like image 30
Leon Avatar answered Sep 28 '22 04:09

Leon


The only way that I am aware of is scraping the regular html response. This can change of course at any time at Googles discretion and I would be interested in a better solution as well.

As of now e.g. the source of http://maps.google.com/?cid=15792901685599310349 has a json response embedded. It starts with cacheResponse([[[ and ends with ]);:

<!DOCTYPE html>
<html dir=ltr>
  <head>
    <script nonce="W6BFnVsL4HLAdFCwYXZY">
      mapslite = {
        START_PERF: (window.performance && window.performance.now) ?
                        window.performance.now() : +(new Date())
      };
      mapslite.getBasePageResponse = function(cacheResponse) {
        delete mapslite.getBasePageResponse;
        cacheResponse([[[2556.225486744883,-122.3492774,47.6205063], ... removed ... ]);
      };
      executeOgJs = function() {

Within this json array element 8 contains a sub array. Element 27 is the place_id.

In case of the Space Needle with CID 15792901685599310349 the place id is ChIJ-bfVTh8VkFQRDZLQnmioK9s.

Only Google knows why they don't provide a better way.

like image 43
Klaas Avatar answered Sep 28 '22 05:09

Klaas