Google Places API Web Service (PHP): how to get 'administrative_area_2 place_id' for a given 'place_id' -


my webapp receives place_id user-selected geo. example: if user chooses on frontend place called "comacchio" (it's town, part of administrative_area_level_2 called province of ferrara) webapp recives place_id comacchio: chij0yhebbb1fkcr7yujotes0da.

when query maps.googleapis.com said place_id, whole lot of information (see below) not 1 need: what need place_id administrative_area_level_2 of input place_id (which chij7y4reyxcfkcrwh-6_aubbwm provincia di ferrara).

as can see below, provincia di ferrara returned string, not place_id 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] =>                 [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 ) 

you can try call google places api web service php administrative_area_level_2 (add country query param, more accurate predictions) value of selected place, like:

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" } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -