From Google Maps CID to Place ID

匿名 (未验证) 提交于 2019-12-03 01:38:01

问题:

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?

回答1:

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.



回答2:

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



回答3:

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.



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