Google Places API Web Service (PHP): How to get "Administrative_area_2 place_id" for a given "place_id"

My webapp gets place_id for user selected geography. For example: if the user selects a place in the interface called "Comacchio" (this is a city, part of administrative_advertising_2, called the Province of Ferrara ) my webapp gets the place_id for Comacchio: ChIJ0yHebbB1fkcR7YujotES0dA .

When I request maps.googleapis.com for the specified place_id, I get a lot of information (see below), but not the one I need: I need a place_id for the Administrative_area_level_2 input place_id (which would be ChIJ7y4rEyxCfkcRwH-6_AubBwM for Provincia di Ferrara).

As you can see below, Provincia di Ferrara returns as a string, but not as the place_id I need.

 Array ( [html_attributions] => Array( ) [result] => Array ( [address_components] => Array ( [0] => Array ( [long_name] => Comacchio [short_name] => Comacchio [types] => Array ( [0] => locality [1] => political ) ) [1] => Array ( [long_name] => Comacchio [short_name] => Comacchio [types] => Array ( [0] => administrative_area_level_3 [1] => political ) ) [2] => Array ( [long_name] => Provincia di Ferrara [short_name] => FE [types] => Array ( [0] => administrative_area_level_2 [1] => political ) ) [3] => Array ( [long_name] => Emilia-Romagna [short_name] => Emilia-Romagna [types] => Array ( [0] => administrative_area_level_1 [1] => political ) ) [4] => Array ( [long_name] => Italy [short_name] => IT [types] => Array ( [0] => country [1] => political ) ) [5] => Array ( [long_name] => 44022 [short_name] => 44022 [types] => Array ( [0] => postal_code ) ) ) [adr_address] => <span class="postal-code">I-44022</span> <span class="locality">Comacchio</span> <span class="region">FE</span>, <span class="country-name">Italy</span> [formatted_address] => 44022 Comacchio FE, Italy [geometry] => Array ( [location] => Array ( [lat] => 44.6940053 [lng] => 12.1793532 ) [viewport] => Array ( [northeast] => Array ( [lat] => 44.7056942 [lng] => 12.2000628 ) [southwest] => Array ( [lat] => 44.6839703 [lng] => 12.15889 ) ) ) [icon] => http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png [id] => cb8042e2b729756e683d2aff008871f9876081dd [name] => Comacchio [place_id] => ChIJ0yHebbB1fkcR7YujotES0dA [reference] => CoQBdgAAAGSwypFqE8NNsCqFFroul7U-c8ACswn9Zd_O89SAK6nxPTpsevzOLaa9rQa0-ms2SXDgnrAxKkQ7av8KHxjRHL0UB_GD_xBzMM2u5iYCDVhoLtwSKMifSJAX7T0q9pdqeB6kzPa3IbLGpdDcaMOOAWZ8gf1gtbNjr9Wf3oo5cV4JEhAWQYrsRynoan3_W0DMElMSGhQb2BUPnW0s_cCUgeHkskTZwSPNeg [scope] => GOOGLE [types] => Array ( [0] => locality [1] => political ) [url] => https://maps.google.com/maps/place?q=44022+Comacchio+FE,+Italy&ftid=0x477e75b06dde21d3:0xd0d112d1a2a38bed [vicinity] => Comacchio ) [status] => OK ) -ms2SXDgnrAxKkQ7av8KHxjRHL0UB_GD_xBzMM2u5iYCDVhoLtwSKMifSJAX7T0q9pdqeB6kzPa3IbLGpdDcaMOOAWZ8gf1gtbNjr9Wf3oo5cV4JEhAWQYrsRynoan3_W0DMElMSGhQb2BUPnW0s_cCUgeHkskTZwSPNeg Array ( [html_attributions] => Array( ) [result] => Array ( [address_components] => Array ( [0] => Array ( [long_name] => Comacchio [short_name] => Comacchio [types] => Array ( [0] => locality [1] => political ) ) [1] => Array ( [long_name] => Comacchio [short_name] => Comacchio [types] => Array ( [0] => administrative_area_level_3 [1] => political ) ) [2] => Array ( [long_name] => Provincia di Ferrara [short_name] => FE [types] => Array ( [0] => administrative_area_level_2 [1] => political ) ) [3] => Array ( [long_name] => Emilia-Romagna [short_name] => Emilia-Romagna [types] => Array ( [0] => administrative_area_level_1 [1] => political ) ) [4] => Array ( [long_name] => Italy [short_name] => IT [types] => Array ( [0] => country [1] => political ) ) [5] => Array ( [long_name] => 44022 [short_name] => 44022 [types] => Array ( [0] => postal_code ) ) ) [adr_address] => <span class="postal-code">I-44022</span> <span class="locality">Comacchio</span> <span class="region">FE</span>, <span class="country-name">Italy</span> [formatted_address] => 44022 Comacchio FE, Italy [geometry] => Array ( [location] => Array ( [lat] => 44.6940053 [lng] => 12.1793532 ) [viewport] => Array ( [northeast] => Array ( [lat] => 44.7056942 [lng] => 12.2000628 ) [southwest] => Array ( [lat] => 44.6839703 [lng] => 12.15889 ) ) ) [icon] => http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png [id] => cb8042e2b729756e683d2aff008871f9876081dd [name] => Comacchio [place_id] => ChIJ0yHebbB1fkcR7YujotES0dA [reference] => CoQBdgAAAGSwypFqE8NNsCqFFroul7U-c8ACswn9Zd_O89SAK6nxPTpsevzOLaa9rQa0-ms2SXDgnrAxKkQ7av8KHxjRHL0UB_GD_xBzMM2u5iYCDVhoLtwSKMifSJAX7T0q9pdqeB6kzPa3IbLGpdDcaMOOAWZ8gf1gtbNjr9Wf3oo5cV4JEhAWQYrsRynoan3_W0DMElMSGhQb2BUPnW0s_cCUgeHkskTZwSPNeg [scope] => GOOGLE [types] => Array ( [0] => locality [1] => political ) [url] => https://maps.google.com/maps/place?q=44022+Comacchio+FE,+Italy&ftid=0x477e75b06dde21d3:0xd0d112d1a2a38bed [vicinity] => Comacchio ) [status] => OK ) 
+6
source share
1 answer

You can try to call the Google Places API web service with PHP using admin_area_level_2 (add the country to the query parameter to get more accurate forecasts) the value of the selected location, for example:

 https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Provincia%20di%20Ferrara,%20Italy&types=(regions)&language=pt_BR&key={private_key_removed} 

The output should be:

 { "predictions" : [ { "description" : "Provincia di Ferrara, Itália", "id" : "b5fa0282b59be22bd0ad64f97011f744db1aeed8", "matched_substrings" : [ { "length" : 20, "offset" : 0 } ], "place_id" : "ChIJ7y4rEyxCfkcRwH-6_AubBwM", "reference" : "CkQ1AAAAqCcMPeJiVWhf2mlBLCJVf82WAxOUARNWqT6NWbp7AEb2nlub1ax3iUMDTKsCAvM_Y6Uylc78mSB_QB5bECVkGxIQxCwIgZ4_WC6fAPJB_N7o0RoU8m_Sdb6CpSyaZeW2lpi9YoJ8bO0", "terms" : [ { "offset" : 0, "value" : "Provincia di Ferrara" }, { "offset" : 22, "value" : "Itália" } ], "types" : [ "administrative_area_level_2", "political", "geocode" ] } ], "status" : "OK" } 
+2
source

All Articles