How to Parse this Google JSON response with PHP? - php

I want to know the place name by Lat / Lng. For that I found Google API. The program I write is
<?php
$url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=13.74349%2C100.489067&sensor=false';
$data = json_decode(file_get_contents($url));
echo '<pre>';
print_r($data);
?>
The output is given below
Array
(
[0] => stdClass Object
(
[results] => Array
(
[0] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Wang Doem 8
[short_name] => Wang Doem 8
[types] => Array
(
[0] => route
)
)
[1] => stdClass Object
(
[long_name] => Wat Arun
[short_name] => Wat Arun
[types] => Array
(
[0] => sublocality
[1] => political
)
)
[2] => stdClass Object
(
[long_name] => Bangkok Yai
[short_name] => Bangkok Yai
[types] => Array
(
[0] => sublocality
[1] => political
)
)
[3] => stdClass Object
(
[long_name] => Bangkok
[short_name] => Bangkok
[types] => Array
(
[0] => locality
[1] => political
)
)
[4] => stdClass Object
(
[long_name] => Thailand
[short_name] => TH
[types] => Array
(
[0] => country
[1] => political
)
)
[5] => stdClass Object
(
[long_name] => 10600
[short_name] => 10600
[types] => Array
(
[0] => postal_code
)
)
)
[formatted_address] => Wang Doem 8, Wat Arun, Bangkok Yai, Bangkok 10600, Thailand
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.7448616
[lng] => 100.4888865
)
[southwest] => stdClass Object
(
[lat] => 13.7445018
[lng] => 100.4876895
)
)
[location] => stdClass Object
(
[lat] => 13.7446807
[lng] => 100.4882883
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.7460306803
[lng] => 100.48963698
)
[southwest] => stdClass Object
(
[lat] => 13.7433327197
[lng] => 100.48693902
)
)
)
[types] => Array
(
[0] => route
)
)
[1] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Wat Arun
[short_name] => Wat Arun
[types] => Array
(
[0] => sublocality
[1] => political
)
)
[1] => stdClass Object
(
[long_name] => Bangkok Yai
[short_name] => Bangkok Yai
[types] => Array
(
[0] => sublocality
[1] => political
)
)
[2] => stdClass Object
(
[long_name] => Bangkok
[short_name] => Bangkok
[types] => Array
(
[0] => locality
[1] => political
)
)
[3] => stdClass Object
(
[long_name] => Thailand
[short_name] => TH
[types] => Array
(
[0] => country
[1] => political
)
)
[4] => stdClass Object
(
[long_name] => 10600
[short_name] => 10600
[types] => Array
(
[0] => postal_code
)
)
)
[formatted_address] => Wat Arun, Bangkok Yai, Bangkok 10600, Thailand
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.7481218
[lng] => 100.4919267
)
[southwest] => stdClass Object
(
[lat] => 13.7361885
[lng] => 100.4803822
)
)
[location] => stdClass Object
(
[lat] => 13.7434901
[lng] => 100.4890647
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.7481218
[lng] => 100.4919267
)
[southwest] => stdClass Object
(
[lat] => 13.7361885
[lng] => 100.4803822
)
)
)
[types] => Array
(
[0] => sublocality
[1] => political
)
)
[2] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Bangkok Yai
[short_name] => Bangkok Yai
[types] => Array
(
[0] => sublocality
[1] => political
)
)
[1] => stdClass Object
(
[long_name] => Bangkok
[short_name] => Bangkok
[types] => Array
(
[0] => locality
[1] => political
)
)
[2] => stdClass Object
(
[long_name] => Thailand
[short_name] => TH
[types] => Array
(
[0] => country
[1] => political
)
)
[3] => stdClass Object
(
[long_name] => 10600
[short_name] => 10600
[types] => Array
(
[0] => postal_code
)
)
)
[formatted_address] => Bangkok Yai, Bangkok 10600, Thailand
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.7481218
[lng] => 100.4919267
)
[southwest] => stdClass Object
(
[lat] => 13.722343
[lng] => 100.4615641
)
)
[location] => stdClass Object
(
[lat] => 13.7341183
[lng] => 100.4761897
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.7481218
[lng] => 100.4919267
)
[southwest] => stdClass Object
(
[lat] => 13.722343
[lng] => 100.4615641
)
)
)
[types] => Array
(
[0] => sublocality
[1] => political
)
)
[3] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => 10600
[short_name] => 10600
[types] => Array
(
[0] => postal_code
)
)
[1] => stdClass Object
(
[long_name] => Wat Tha Phra
[short_name] => Wat Tha Phra
[types] => Array
(
[0] => sublocality
[1] => political
)
)
[2] => stdClass Object
(
[long_name] => Bangkok Yai
[short_name] => Bangkok Yai
[types] => Array
(
[0] => sublocality
[1] => political
)
)
[3] => stdClass Object
(
[long_name] => Bangkok
[short_name] => Bangkok
[types] => Array
(
[0] => locality
[1] => political
)
)
[4] => stdClass Object
(
[long_name] => Thailand
[short_name] => TH
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Wat Tha Phra, Bangkok Yai, Bangkok 10600, Thailand
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.7481218
[lng] => 100.5127718
)
[southwest] => stdClass Object
(
[lat] => 13.694656
[lng] => 100.4615641
)
)
[location] => stdClass Object
(
[lat] => 13.7247046
[lng] => 100.4958678
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.7481218
[lng] => 100.5127718
)
[southwest] => stdClass Object
(
[lat] => 13.694656
[lng] => 100.4615641
)
)
)
[types] => Array
(
[0] => postal_code
)
)
[4] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Bangkok
[short_name] => Bangkok
[types] => Array
(
[0] => locality
[1] => political
)
)
[1] => stdClass Object
(
[long_name] => Thailand
[short_name] => TH
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Bangkok, Thailand
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.9551109
[lng] => 100.9384077
)
[southwest] => stdClass Object
(
[lat] => 13.4940968
[lng] => 100.3277368
)
)
[location] => stdClass Object
(
[lat] => 13.7522222
[lng] => 100.4938889
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.9551109
[lng] => 100.9384077
)
[southwest] => stdClass Object
(
[lat] => 13.4940968
[lng] => 100.3277368
)
)
)
[types] => Array
(
[0] => locality
[1] => political
)
)
[5] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Bangkok
[short_name] => Bangkok
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[1] => stdClass Object
(
[long_name] => Thailand
[short_name] => TH
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Bangkok, Thailand
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.9551109
[lng] => 100.9384077
)
[southwest] => stdClass Object
(
[lat] => 13.4940968
[lng] => 100.3277368
)
)
[location] => stdClass Object
(
[lat] => 13.7234186
[lng] => 100.4762319
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 13.9551109
[lng] => 100.9384077
)
[southwest] => stdClass Object
(
[lat] => 13.4940968
[lng] => 100.3277368
)
)
)
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[6] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Thailand
[short_name] => TH
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Thailand
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 20.465143
[lng] => 105.636812
)
[southwest] => stdClass Object
(
[lat] => 5.612851
[lng] => 97.343396
)
)
[location] => stdClass Object
(
[lat] => 15.870032
[lng] => 100.992541
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 20.465143
[lng] => 105.636812
)
[southwest] => stdClass Object
(
[lat] => 5.612851
[lng] => 97.343396
)
)
)
[types] => Array
(
[0] => country
[1] => political
)
)
)
[status] => OK
)
)
I don't know how to grab the address_components at the top. I try with $data[0]->results[0]->address_components and etc. But it is not working. Please check this once... Thank you.

The following works for me:
$data->results[0]->address_components[0]->long_name
You might also want to enable json_decode's assoc-parameter so that objects get converted to associative arrays.
E.g.
$data = json_decode(file_get_contents($url), true);
$data["results"][0]["address_components"][0]["long_name"]

Related

getting array value from json array PHP

i am using google place json array
json array
i am using this code to get name of place
$string = file_get_contents("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&rankby=distance&types=food&key=AIzaSyCpOG91fkAzPTZiFq7G9HbLfbmVyW8Wgyc");
$json_a = json_decode($string, true);
echo print_r(array_values($json_a-> results[0]->name[0]));
but the result always { 1 } where the result should be Biaggio Cafe
here if i print out the array print_r($json_a)
Array ( [html_attributions] => Array ( ) [next_page_token] => CqQCFwEAAN1f0rbnMkVsdezGGV9kDlKiYdkDKgOSeaul7JL6GFEeLhV0-h3_WHa0NGbQ_here u_N7K3e7r5xxtW4FGjp6dHK4WKxUb1LPbmLq4KvybiR7QyYspK6wHC4In7Slnhj_0veXd25lruweEKFTmnu6fX0JUN3Lwtyz4KnQrnGeJHX7Ldr6oWJcSn-ilM2AXCQi0LnFza4dJmlvh62Eq583kQ5s1WQO8VrnQ8G66Yfy69X7Glbe0Pijj384gSWncN6kEbEUAw_PyHe4R3z50MRa336ZpzTxOulRwjV6NtNtUbn-j-omj0fb2Q0Yf6QQRrmiAaKx2QqYaN3AB7oH1YouLKLyGVzA3qOoIdYmI3OAztgkPKWUlNl5PzS3Ro7V8g-RdNN0hIQTtLlDEzmNPviMy1X28gkHBoUQxlMdi3EX_zrQzljRF12sjVab2c [results] => Array ( [0] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8669667 [lng] => 151.1958862 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.865664669709 [lng] => 151.19708633029 ) [southwest] => Array ( [lat] => -33.868362630292 [lng] => 151.19438836971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png [id] => 7eaf747a3f6dc078868cd65efc8d3bc62fff77d7 [name] => Biaggio Cafe [opening_hours] => Array ( [open_now] => [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 3036 [html_attributions] => Array ( [0] => Briggs Soria ) [photo_reference] => CmRaAAAAcPXEEuCbXQiIU-c0rFzFwHhpmRPEDkZ-7D6ep2gpkEG8Yyx6-aB6o4cp2LWce728a-Eb9izN9ju-TAe6sdURdcpX-UpJwMHR7Ynj1H4HYy7R4WUWtqxbN7hifOWqV6TzEhD0g0k5X-KCKBu9RdWpl-47GhQwPBWXcBL0LnMWEp9ItV7REPcmTQ [width] => 4048 ) ) [place_id] => ChIJIfBAsjeuEmsRdgu9Pl1Ps48 [price_level] => 1 [rating] => 3 [reference] => CmRSAAAAiI3HIH3xQoIx0spB-d1aye7c7W4L3s25RxdAHwwLVEvC5AovkxwscFsfi-1ZKAL9V-DAPda5d9FH_ywnl7Ll3vovPw5v6T08uNxVwJyMn9MPJFHWZN06dJT1f50vZ19qEhBfOVCaYhc8f9tk2UZLkgAOGhSSKLENUQ1taZOQWolQVsJ0V48bQA [scope] => GOOGLE [types] => Array ( [0] => cafe [1] => restaurant [2] => food [3] => store [4] => point_of_interest [5] => establishment ) [vicinity] => 48 Pirrama Road, Pyrmont ) [1] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8671288 [lng] => 151.195339 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866065569709 [lng] => 151.1960316 ) [southwest] => Array ( [lat] => -33.868763530292 [lng] => 151.1932612 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png [id] => 8bdf85385635caa3b9df55ec23d533ceb0f2b8c6 [name] => The Century [opening_hours] => Array ( [open_now] => 1 [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 1989 [html_attributions] => Array ( [0] => The Century ) [photo_reference] => CmRaAAAAbC2XEW4KdedbESdFb1Bgija2OV_9mR8t6DJqMZwmLjwXAtG5JgWYfzUi7nEx0ZKqhhsDxtPceC3MPKbYJIVh7VWT_CDvsN7hRtW2bdpxss87I9DbTn450Vd7dn0wOueWEhBGiONsANF-eOu1xwrVMXP4GhTqtBdrIP84yK19IXGwZVqazpEACQ [width] => 2048 ) ) [place_id] => ChIJ1-v38TauEmsRNrXszdcSywQ [price_level] => 2 [rating] => 3.5 [reference] => CmRRAAAAyJYatPQTSvqMbOt1gIhNxfc1Sy7fnXKDBaX0lYkx16_u2HEu8hyBH_XriKc1Aciq3Gx8FxQI_OkXxRTFh2xz8eJbV8lOA6gFoMxDbvV3nQN2yCAwwgwo60wTKavRnxcOEhBT6whUoikUKFrq4EXRcK4OGhRgUy8KHjA9IS8ckfED_CNkdScvvg [scope] => GOOGLE [types] => Array ( [0] => restaurant [1] => food [2] => point_of_interest [3] => establishment ) [vicinity] => The Star, 80 Pyrmont Street, Pyrmont ) [2] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8667062 [lng] => 151.1957844 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.865427419709 [lng] => 151.19697313029 ) [southwest] => Array ( [lat] => -33.868125380292 [lng] => 151.19427516971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png [id] => fd0f490655de01f49b604781f944340f6623d1b1 [name] => Biaggio Cafe [opening_hours] => Array ( [open_now] => [weekday_text] => Array ( ) ) [place_id] => ChIJA0NrtTeuEmsRkmB_OMsgGOw [reference] => CmRSAAAANgrbbAHDKaIJ1OR0BFJ6t2Jlk0fKKDN9-hnfaDtSU2Xirm_66SOV4Wpy_w7HL6WVv0JXy4vrUdWkLMVizwGS1XpjSqDs-M6WbzSyGr6C-gJdLCUwDMPf6RBpCfeo279REhApljm2GRCvCVzFqcZ0pkGqGhRttJFZd6bXU67b3i-YN-N7ucP2oA [scope] => GOOGLE [types] => Array ( [0] => cafe [1] => restaurant [2] => food [3] => point_of_interest [4] => establishment ) [vicinity] => 48 Pirrama Road, Pyrmont ) [3] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8667062 [lng] => 151.1957844 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.865357219708 [lng] => 151.19713338029 ) [southwest] => Array ( [lat] => -33.868055180291 [lng] => 151.19443541971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png [id] => 3ef986cd56bb3408bc1cf394f3dad9657c1d30f6 [name] => Doltone House - Darling Island Wharf [opening_hours] => Array ( [open_now] => [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 843 [html_attributions] => Array ( [0] => Doltone House - Darling Island Wharf ) [photo_reference] => CmRaAAAAkdwvY7mKPHP6aCqmXjNPithGEIBaytETIG8GtU70vtAsymKWMaYhw4-VW6_W3HKyH9ddeVjnRFWwmWFlZO2yNLZ8IPDGmPSbqqtA4TzwZL9XddUH1eBGg-BhlicwYUTYEhAnqcUR2JQcwa8O54DUD1_XGhRGg60_1NqarQ1UbtXiJzaPq5MtxA [width] => 1500 ) ) [place_id] => ChIJ5xQ7szeuEmsRs6Kj7YFZE9k [rating] => 4.2 [reference] => CmRSAAAAVzanf0yiJg-X4Y2F94Wj-SjxZLi7i4zwrXM-0mEkXgmzelK7Jus6fGWbKsqeGH8fSbzn8oNBGhyV5VvewU4AXFoUx5uMjrg6A5Ho8vccsfL0Dq5PMReQiXYUKYBDoXPNEhCmcU6_Vat2qDmjKaPtJIeYGhT2c8QasUnZCrUQpd_RFUO1_Jf6lQ [scope] => GOOGLE [types] => Array ( [0] => food [1] => point_of_interest [2] => establishment ) [vicinity] => Ground Floor, 48 Pirrama Rd, Pyrmont ) [4] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8667062 [lng] => 151.1957844 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.865357219708 [lng] => 151.19713338029 ) [southwest] => Array ( [lat] => -33.868055180291 [lng] => 151.19443541971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png [id] => 2de2d85c0465dafc9a75e0304859c5ceedb4a679 [name] => Signorelli Gastronomia [opening_hours] => Array ( [open_now] => [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 390 [html_attributions] => Array ( [0] => Signorelli Gastronomia ) [photo_reference] => CmRaAAAA5VEkXQg5NXRvvbjQ-sHCF1rusIPBRItqIXb7ctqawTC8_ZG4b0zPBGBLSA8ttYHp1D2DFFaqT0WtsXLT0tmSBXnJ47-Ei94jKjg5jCIpWt5dlweWMMyx5duOEBNB2biLEhBZqLCcaoSa2tVU6zZEWewGGhQ9JSj_mVqMDeizYtrcYVaCYVz6sQ [width] => 960 ) ) [place_id] => ChIJFcJDMzauEmsRy81NJCujoY8 [price_level] => 2 [rating] => 3.9 [reference] => CmRSAAAAJcg6WX2L8zTXoizEVUB5lyaKW22-sMoMsiOBaT8Oa4stB2PrbrObqZ2boBIIR8xxpyFIpf7q-HZuuDp3oXJ4Wa964l1koOq7jEjk7l_2wFHWdAsEF0ekpmvZV4rTC_nTEhAfwAlxYeqXvgmAL5vBlEjuGhSkxSkyhxCJOZo2gr4lUa7YU5NSww [scope] => GOOGLE [types] => Array ( [0] => food [1] => point_of_interest [2] => establishment ) [vicinity] => Ground Floor, 48 Pirrama Road, Pyrmont ) [5] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8664812 [lng] => 151.196061 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.865132219708 [lng] => 151.19740998029 ) [southwest] => Array ( [lat] => -33.867830180291 [lng] => 151.19471201971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png [id] => 91509349e192972859b886e62f11827e5bd0072f [name] => Esky Cafe [opening_hours] => Array ( [open_now] => [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 1536 [html_attributions] => Array ( [0] => Paul Toogood ) [photo_reference] => CmRaAAAAWHv_VoJ9mDttpdl8XXeM78_bDtutVfhNIwoz57Va1CEzOrxzN5XAtuu1OwzwU8NoH6prpkLzdALY0DhdKz4reJkejB_AV4NYrbFbztRRG5xcJGthqTHOzzdDXzBTkPk-EhDVmJVlHn-tap_okguRQ4eKGhQ78ZojGOFEKHxpPeJGTBaNa68yDg [width] => 2048 ) ) [place_id] => ChIJm3d7yTeuEmsRC2wYUB24q9I [rating] => 4.4 [reference] => CmRSAAAAOEtb2LjP1kZkWxsgcq5mGm6NWlAlwMOTXQnF3HFvwRN9-cIl0-RJU8-nT3Jp8dRlib9o0M2U0JFauLwjjOw0fqPadh2OBVqGde8LqbzVP4FUIlmKR-lKOCuC1U8Fyw1QEhB0T-m_Jh_h4ooBbl4YxQQOGhQC_bkk9d2Fyraihp5Q6-njdS1QEg [scope] => GOOGLE [types] => Array ( [0] => restaurant [1] => cafe [2] => food [3] => point_of_interest [4] => establishment ) [vicinity] => Workplace 6, 48 Pirrama Road, Pyrmont ) [6] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8677499 [lng] => 151.1956285 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866673069708 [lng] => 151.19631778029 ) [southwest] => Array ( [lat] => -33.869371030291 [lng] => 151.19361981971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png [id] => b21cfc23b85bda32717dc32bbb3b0d290e1692bf [name] => Kampung [opening_hours] => Array ( [open_now] => [weekday_text] => Array ( ) ) [place_id] => ChIJ1-v38TauEmsRkfBaAXNA5LI [rating] => 5 [reference] => CmRSAAAAh9Vuux8EylTbKIFyoWDxeWXxXHp8fsNM7Q97h8W9_TxvAo23lTjahLW0vGFAnlmHG3qIu4WXfo5XlgS42tQIsp5RiAiFiuqLtlXX1uRI4JxJrpi3oSxCp75fRlxGJsgrEhB2JLQK_7pdw-RhP6XDi12XGhTcmREuPiKty8znAmNvc1VPE2Unvg [scope] => GOOGLE [types] => Array ( [0] => restaurant [1] => meal_takeaway [2] => food [3] => point_of_interest [4] => establishment ) [vicinity] => 80 Pyrmont Street, Pyrmont ) [7] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8677499 [lng] => 151.1956285 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866673069708 [lng] => 151.19631778029 ) [southwest] => Array ( [lat] => -33.869371030291 [lng] => 151.19361981971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png [id] => f67efa5095d123ed2c1ce28e9297cc1e04624dc8 [name] => Lotus Pond [opening_hours] => Array ( [open_now] => 1 [weekday_text] => Array ( ) ) [place_id] => ChIJS_-h7TauEmsRdmDJ2CvXToY [rating] => 3.2 [reference] => CmRSAAAApnMGhFr1SKg2H4LpIDfJXqOAy2OUDSy_NaWA6ZOetI47fBG-Un_heBunbN2ozjyuhac5z7MHXOCwlGchZRpOJtOJupqfhOHGP93S2fvSTUt8nLUUo39WKBvpHUMrfCKmEhBuSr4HMwgKwUJkpjT5ffUnGhRQejzefZ3S3vCStqCxF8wAlBt1JQ [scope] => GOOGLE [types] => Array ( [0] => restaurant [1] => food [2] => point_of_interest [3] => establishment ) [vicinity] => 80 Pyrmont Street, Pyrmont ) [8] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8677499 [lng] => 151.1956285 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866673069708 [lng] => 151.19631778029 ) [southwest] => Array ( [lat] => -33.869371030291 [lng] => 151.19361981971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/bar-71.png [id] => 882abf952e4d0e6dd96294459abe076c90c127dd [name] => 24/7 Sports Bar [opening_hours] => Array ( [open_now] => 1 [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 638 [html_attributions] => Array ( [0] => 24/7 Sports Bar ) [photo_reference] => CmRaAAAAYsUMTqwU7RRG7gB1ft1yChuVhIvF4_TZ1NBRyyQdQs163bRXTh0X2ZJ_4AzjnNQztgZgOFxieDONaMGfqBlfQ3GWjgMFPZ3m-Ut-UsumAyDi2FQoo25vDBp58CA2kfdwEhDhNViiTe0vPZz2FgiFPphqGhTx1ZfQLwYRebnXV4I0q8yS1VF1Sg [width] => 960 ) ) [place_id] => ChIJ77Cd7TauEmsRBV42CMtSans [rating] => 3.4 [reference] => CmRRAAAANyqljC8u7sy67zaoKmvy1yZF9BJcoCO4UBwiC0F6WIPMkhZo84UbBiyR_bngCy8mziKacKR7hqOmH0C5YqJryYPNSpHqeTahBB84i7wnezFrFYklzHCjDTt_DhDFW96mEhBXRQVuWptLLxd9XRES6X3pGhQF3k1348GfUaIlUVmFiE06ERWP6w [scope] => GOOGLE [types] => Array ( [0] => bar [1] => restaurant [2] => food [3] => point_of_interest [4] => establishment ) [vicinity] => 80 Pyrmont Street, Pyrmont ) [9] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8677499 [lng] => 151.1956285 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866673069708 [lng] => 151.19631778029 ) [southwest] => Array ( [lat] => -33.869371030291 [lng] => 151.19361981971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png [id] => e188acf29a29bc46f1cf844c0bf78f8b1464bd6f [name] => BLACK Bar & Grill [opening_hours] => Array ( [open_now] => [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 2160 [html_attributions] => Array ( [0] => Chopinand Mysaucepan ) [photo_reference] => CmRaAAAAwz1MNHctvLtTgc7iFYmuDljnVuWyKnajNBh0z24Il7cTm7TAiJlAlnzvsgUp5JVULO8_oPFxW6DkjKLqN-MI0T703nJzFYGT79Yx36tJxuZaBAkZ5xIAis7T51pXYQ-wEhCupMDWqDDxv_3YsfJZnsQPGhQBp2vGHZWl6ECDGdoGt17Hz28PJg [width] => 3232 ) ) [place_id] => ChIJ9ZCzFzGuEmsR_EwB_qra-W4 [rating] => 4.1 [reference] => CmRRAAAAkRe25ds64LLF7mzx0Qdiy-d2kqa1WQzeNHH6_SsiDeZFdzjorMWenC7z4VRTw7BdNocoPzjqb6AjICSKQZCR6fW_xVHmsEUQNJseFAJ-6hDlgv2PpoBJ9pU5PnK221T3EhBJ3CwsMrtaSdukyZyDIpWvGhSeLY4vgz6nO6ZSW5bb0gcQsJxIOQ [scope] => GOOGLE [types] => Array ( [0] => restaurant [1] => bar [2] => food [3] => point_of_interest [4] => establishment ) [vicinity] => G, 80 Pyrmont Street, Pyrmont ) [10] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8677499 [lng] => 151.1956285 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866673069708 [lng] => 151.19631778029 ) [southwest] => Array ( [lat] => -33.869371030291 [lng] => 151.19361981971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png [id] => 8ed2a95d07a89918c0a1b846544a955b36820af3 [name] => Dergah Grill [opening_hours] => Array ( [open_now] => 1 [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 992 [html_attributions] => Array ( [0] => Dergah Grill ) [photo_reference] => CmRaAAAAjsOwnxHbfcRXNSsW7sVFA88bbK7XoeeI8etp5i3Rkmfvw2Nv2oOGbVoJzNZrzUwBrFpTRv_pU27OzahrLlCUFFLGz-_P2Z7Hn4jH0waC4urQg18yPbyE2qHFXRAh2sF_EhBK6Dk08w1Z44NTsgzbBVSMGhRLCr0qizP00LjX_T6jUh_986vnWA [width] => 1487 ) ) [place_id] => ChIJ1-v38TauEmsR7cWnOpSlMWU [rating] => 3 [reference] => CmRRAAAAz-ES7KMUShGEIn28_6aURVGtGr3kEJR9SzWKTgvXo9QDYSJAIVSe2WD02y4H9aJEv3IXJUTl1wH4iMxivWmNwNNJoSCotqKo7Dky9K4dpVSKwSLJvyGA65G1tuHzswMzEhAz3rOaYTJh9qr42kVmFeFdGhQwYDAjO2IYp6ypv5ot-QFZvZzJOA [scope] => GOOGLE [types] => Array ( [0] => meal_takeaway [1] => restaurant [2] => food [3] => point_of_interest [4] => establishment ) [vicinity] => 80 Pyrmont Street, Pyrmont ) [11] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8677499 [lng] => 151.1956285 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866673069708 [lng] => 151.19631778029 ) [southwest] => Array ( [lat] => -33.869371030291 [lng] => 151.19361981971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png [id] => 5895b175f4c2a8535294f5587fe089fc7d5135ea [name] => Pulse Express [opening_hours] => Array ( [open_now] => [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 992 [html_attributions] => Array ( [0] => Pulse Express ) [photo_reference] => CmRaAAAAg1N3QTCieHLyOJE0-UsbTQJJnawb4ZTuoB_-WPf9Wz4fOQbtJGvRWbUnppV_RgKaq5heQuEMBGg9kI0iXGxrDVPOEnQ3Zyh-iLbge3xpuZyQI0mjS6BlvyxRdNPvn3lVEhChKRAL5I5nHP_QU_a7aJjWGhTlwb7eywRH-kh7dx-spnPvP4bUXA [width] => 1618 ) ) [place_id] => ChIJ1-v38TauEmsRJxe1QBBHBGU [rating] => 2.6 [reference] => CmRRAAAALsYqD7jAxdAy8zpoDEWxfFD9PFNlJdN8o-krm3fupp77oxNnP-fJJqvplpFIxWTFA1pjVwFG0ozgeao2PhoL0VoKPDT6Gy6qi56NKyusNn6eDkfzLctO3iDB4Dx_inomEhAjhFof0CLWU1vFJ4VMOfvjGhSVYSHLz7kQml-Ne-VJVJuawxywRg [scope] => GOOGLE [types] => Array ( [0] => cafe [1] => restaurant [2] => food [3] => point_of_interest [4] => establishment ) [vicinity] => 80 Pyrmont Street, Pyrmont ) [12] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8678337 [lng] => 151.1958116 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866484719709 [lng] => 151.19716058029 ) [southwest] => Array ( [lat] => -33.869182680291 [lng] => 151.19446261971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png [id] => f138865c7ac72dcc2cbd0491710aa6203ebc595f [name] => Pizzaperta [opening_hours] => Array ( [open_now] => 1 [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 440 [html_attributions] => Array ( [0] => Pizzaperta ) [photo_reference] => CmRaAAAADCeKPVnBAGuxYOy03lNLG-7HuR5VQ6fBNFQmvJsCX52UBYB_wV4_450EskliO7fGWAwZ6mXhNLgonnqp0I9ixGFOeWzBuT2ChqPPoET9ofpKYiwNi9t4d7fl5NQTYyc5EhCxeM8QlMlbKP65Mku5ZAnDGhQR-zt6WCXpQXmhJ5gmXSdamamTWQ [width] => 700 ) ) [place_id] => ChIJA6-_qzeuEmsRiV9SAHIbzh4 [rating] => 3.4 [reference] => CmRRAAAAn-uUOFjUKSV18ENqqy65iOzr3Ea1H3ipK-9c3UX1IsTJPgb_-gd6d4BrsUIDcKZmwAnQZ8rtesI8jA0V46-9ovQh9RiGXmJsLrz3UyrKSxkhOuLXvFzyKu2z3Ja8QbGMEhDo-m7u5hyHfMmgPTcdKsWOGhRo5Fizn7eEefTbuOl9D8GfMAmX8A [scope] => GOOGLE [types] => Array ( [0] => restaurant [1] => food [2] => point_of_interest [3] => establishment ) [vicinity] => The Star Sydney, Harbourside Entry, Pirrama Rd, Pyrmont NSW 2009, Sydney ) [13] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.867931 [lng] => 151.1958456 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866582019709 [lng] => 151.19719458029 ) [southwest] => Array ( [lat] => -33.869279980292 [lng] => 151.19449661971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png [id] => 372b98902d4032b2708939131b8bc6bfbce9044c [name] => Chao Praya City [place_id] => ChIJ1-v38TauEmsRwCiun0VT1Kg [rating] => 5 [reference] => CmRSAAAA4HOsgFazyJOqUAEAfPyuQif3apB-IrYQ_UVZTyvwYLm18txQlrvMOWcaZp98ggKyWEoA0ea17TSlUNwHxJt3YLAOY_Aj6JSaOtRWxl3HdIoGwFGpVzVo37OyXen7d5nCEhDy43UD1zpBwgahbZGtW7nBGhRiLaMA4r9IsOXzLTe7-tm-ZzDNRA [scope] => GOOGLE [types] => Array ( [0] => restaurant [1] => food [2] => point_of_interest [3] => establishment ) [vicinity] => P1 Level G Star City Pirrama Road, Pyrmont ) [14] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8680279 [lng] => 151.195857 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866961369708 [lng] => 151.1965416 ) [southwest] => Array ( [lat] => -33.869659330291 [lng] => 151.1938032 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png [id] => 08c0f74375ca1956d8ae2919512171adcd8266d7 [name] => Balla [opening_hours] => Array ( [open_now] => [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 2882 [html_attributions] => Array ( [0] => Cynthia Chia ) [photo_reference] => CmRaAAAAQ3bhhMFaAoi-XSdDMIl1abzVHbm92X575sZ--9E828fgDgt1va8s8to_iCVMjruKD-E2vECITkXW_hwBP9iS4NE8fJSyEj2ZrK6eCP5HAiafZJT0DUsRkiWxVQ66Ud8mEhBDEgwL9JaYlPOaTIlT81MpGhTK_Bmrs14OfusC2d7vJ3SoRIUiKw [width] => 3843 ) ) [place_id] => ChIJ1-v38TauEmsRFBHuvMmwNyA [price_level] => 3 [rating] => 3.7 [reference] => CmRRAAAAxa4gkSU26kt1A9BMsaxySAdOysJGpreX08qD8FY-w40v6J36GYo1xIZJ9vy-T8zbjNLXr1PEXD458O72KpZr83kNlEuZIMYxQcodSdkAFtMJzbsaCCm2ldzYjeF-cDM1EhDLMSnhPjgnj33vJn13HV6GGhRNG8bcAGL_d9kMXxMMxfJjjGyffA [scope] => GOOGLE [types] => Array ( [0] => restaurant [1] => food [2] => point_of_interest [3] => establishment ) [vicinity] => The Star, G, 80 Pyrmont Street, Pyrmont ) [15] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8679022 [lng] => 151.1951276 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866727419708 [lng] => 151.19605433029 ) [southwest] => Array ( [lat] => -33.869425380291 [lng] => 151.19335636971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png [id] => 0761a21e23eda2598330d428413cb59431316a61 [name] => Lobby Lounge [opening_hours] => Array ( [open_now] => 1 [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 1632 [html_attributions] => Array ( [0] => Andrei Setiawan Yohannes ) [photo_reference] => CmRaAAAA5WtwRlnY-IB_agGsXdnruKoylr826EKf-vmptRBP68TXnQPuT5DPGByyl9VCMiC-_tt7PGY-qVVoXQnEue-fS9S2oWyyiUoXA_XTnriNyC0TasEwfyqMI2tHnfEn4r_5EhBZpIz5HXkqmqBK6HQhxQ4yGhRBLF-Xg9yILQPoB8KW4bT6xJn1Ag [width] => 920 ) ) [place_id] => ChIJ1-v38TauEmsRHbUt24abGq8 [rating] => 3.9 [reference] => CmRSAAAALvC6LDeHGtKa-1BfrK8GxGZJms5-W23jkxgNHUNfUAWST9IIfNzcqPKy7MMuaLztr5sIZpIiEs5YBhM4PtAccuBSdJSx5LaWK-E5ObIs_LZPCwtOikhG0NMtAf6D_hbpEhD2eT7U7sfSDnKg98_RWkd8GhQD3C5E8vTUxAO_p1GxO7w5oYtcCw [scope] => GOOGLE [types] => Array ( [0] => cafe [1] => food [2] => store [3] => point_of_interest [4] => establishment ) [vicinity] => 80 Pyrmont Street, Pyrmont ) [16] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8679658 [lng] => 151.1952022 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866350469709 [lng] => 151.19779985 ) [southwest] => Array ( [lat] => -33.869048430291 [lng] => 151.19280965 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png [id] => 44fdc977984610cd873c790a7d850e8185ed0e5e [name] => The Star Sydney [opening_hours] => Array ( [open_now] => 1 [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 1978 [html_attributions] => Array ( [0] => The Star Sydney ) [photo_reference] => CmRaAAAAAKL4p8pfqn9KTX1IP4mC6wbRpfJB2R8wdaAT7y6fmdLL8-5XIdgggJp31eE9S0tJQbifbUqDCCjqH1YK74u2ezYck-6_m7MB7FG9fBCKcW_gv5Utyt5nHcC2IiW7GpfFEhCNnJ_cBhkAaSf9vcmYiQ0SGhROkORa05CJzj2d8kBLLRdg6q39OA [width] => 2048 ) ) [place_id] => ChIJq6qq6jauEmsRJAf7FjrKnXI [rating] => 4 [reference] => CmRRAAAAP2aFIXavvX5VXtZkh_BsYrNfKlzYMJS-LeoZWPUzOaY96nVOpuANmGxyBnS-A25653IYjCOBOqGpNTLYdUALm75rICJmk9BkV29IHuS11I-gKFgviOkQnjC-QDMU6NMOEhDvOnNCgVPkvBeXh5KWnKDGGhT5qVnYHznM3i7qGh_bvJ3Vv2uGBA [scope] => GOOGLE [types] => Array ( [0] => casino [1] => spa [2] => lodging [3] => restaurant [4] => food [5] => point_of_interest [6] => establishment ) [vicinity] => 80 Pyrmont Street, Pyrmont ) [17] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.867978 [lng] => 151.195171 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866802919708 [lng] => 151.19609848029 ) [southwest] => Array ( [lat] => -33.869500880291 [lng] => 151.19340051971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png [id] => 7d4beb38f8a160ca1758002b846afbf713cfe432 [name] => Vantage, The Star [opening_hours] => Array ( [open_now] => 1 [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 3024 [html_attributions] => Array ( [0] => Neek Woman ) [photo_reference] => CmRaAAAA09pV6Ak9le5QPb1Djz9eCeBAK1MaBhTjF_XWBw-OdOwDP3xY-vHGjnC7RK8lRUd6qZ6OFccb3woPGGZxL7C4v-MVThoMqRfbYVaET-GQoN6OgFFFXtluaR-fYSj2k_IFEhCPSwX1E1O_Bb2Pz49_GYvUGhSr70Gmld6MWqoTdMkgm00mkl4S4w [width] => 3024 ) ) [place_id] => ChIJ2fIN-TauEmsRj8cqw1d-YI0 [rating] => 4 [reference] => CmRSAAAALWJKfuthS5deCrLk_fBqSMVa_cXG5uBPDFrF5ifHvitgFsdOfhkzgW4-58x6qfRdm2m5kJE950tJ-z7w6V3K7eDqF8P00O-gJIfWQg6agRh3L-5WZdKvgqfMZd6JLmfOEhCNSI1TqwbYLWWT-xTs2mLHGhTeOfVM-lR9v9jMlJvPa7pqk_aucg [scope] => GOOGLE [types] => Array ( [0] => restaurant [1] => casino [2] => food [3] => point_of_interest [4] => establishment ) [vicinity] => 80 Pyrmont Street, Pyrmont ) [18] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.8669724 [lng] => 151.1944552 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.865714269709 [lng] => 151.19589088029 ) [southwest] => Array ( [lat] => -33.868412230291 [lng] => 151.19319291971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/shopping-71.png [id] => dd8ce7e0a6f502325a4a5f45abfa2e1dc3784e07 [name] => Ezy mart pyrmont [opening_hours] => Array ( [open_now] => 1 [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 899 [html_attributions] => Array ( [0] => Ezy mart pyrmont ) [photo_reference] => CmRZAAAAxwL2stPwv920nCiDOd3qm8bUIZZ3DAolWumYyMOpjKSjo6kYnO_YDoHzWFICKERPnIPucrIbdOrP8oY06LKBkaVLWX9UwPiMugbCcpAt5bZjT2PDhnwT8S4fleleT4pFEhC47nMqVf_XsAOtVVK0quhkGhR4_lUCOwYmhQib9FhrxKpdTHWA8A [width] => 900 ) ) [place_id] => ChIJV37FXDauEmsRL6aHZGJ7Q04 [reference] => CmRRAAAAtFUKLoOXju5F3e6L_dVsuKxI2jeXsraJOdU9Ilzg2U66aJb-TSB9OacxmgovqGQhb6I9nUOIQnUmDdgJsPEaziy9xf7ztkNKMj1VemSjzLeFnF95SB0bUAyu0L25Fj-4EhC1FPac5lMJy-FmkPWdm5EyGhSlBzIOA3oqBAiszlxbCL7BTy4IRw [scope] => GOOGLE [types] => Array ( [0] => convenience_store [1] => food [2] => store [3] => point_of_interest [4] => establishment ) [vicinity] => 1/2 Jones Bay Road, Pyrmont ) [19] => Array ( [geometry] => Array ( [location] => Array ( [lat] => -33.868028 [lng] => 151.19521 ) [viewport] => Array ( [northeast] => Array ( [lat] => -33.866679019708 [lng] => 151.19655898029 ) [southwest] => Array ( [lat] => -33.869376980291 [lng] => 151.19386101971 ) ) ) [icon] => https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png [id] => ba9494fbebdb7e40f9a646aab93379212763195c [name] => Fat Noodle [opening_hours] => Array ( [open_now] => 1 [weekday_text] => Array ( ) ) [photos] => Array ( [0] => Array ( [height] => 469 [html_attributions] => Array ( [0] => Fat Noodle ) [photo_reference] => CmRaAAAA0zMsUGM3z6dLIJmGiOcA39rcUNhUSJJlNQAAqqEbQzOiWhTeYAAdfJsjB1aBIHtDysC3CJwyHxKXmpXweRBv2G0-60FZVdawXVRiTyA2KTnG-2qgAm6h9k2FfDIzhsUIEhB2XzrAKGRuxOEnCowpQ8i1GhT-FQbOYvsdFgdhR6QdRwBsOKjIrA [width] => 750 ) ) [place_id] => ChIJ1-v38TauEmsROWultgmCYW0 [price_level] => 1 [rating] => 3.2 [reference] => CmRRAAAAlCa7aYxV6SgfJZII_AqswB88Oo2q0--NWOibat1k2OuiuBenPkZ3IKbTB-d8iQg2AupBZxtaY4DuS27eE1YYNrlZ4kRk2G7IaY2j9uP73zpZNT7KS8ASw2ibmiCM9Y2hEhC2fpgHMn6HxPpTpDS-Sts2GhQB3NhqtuZKtouPwU4j0jXFlz0NzQ [scope] => GOOGLE [types] => Array ( [0] => restaurant [1] => food [2] => point_of_interest [3] => establishment ) [vicinity] => The Star, 80 Pyrmont Street, Pyrmont ) ) [status] => OK )
Checking at the structure of the json got from the call, to access the value you want to need to do like this.
$string = file_get_contents("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&rankby=distance&types=food&key=AIzaSyCpOG91fkAzPTZiFq7G9HbLfbmVyW8Wgyc");
$json_a = json_decode($string, true);
print_r($json_a['results'][0]['name']));
Results is an array, and you want to access to its first element ([0]). From that first element you want to get the property name. And all the properties on the element are set inside an array, so you need to access it by the property name.
You were using the object operator (->) to access elements from an array, that's why it didn't work.
echo print_r(....); is in a way redundant. print_r it self prints result to output in similar way as echo and returns TRUE which is what you are printing.
From documentation:
mixed print_r ( mixed $expression [, bool $return = false ] )
When the return parameter is TRUE, this function will return a string. Otherwise, the return value is TRUE.
Either do not use echo or set the return param to TRUE.
echo print_r($array, true);

get country, region and city name from longitude and latitude (PHP)

I would like to get country, pincode,state and city name from longitude and latitude over Google maps API - with PHP. but sometimes it works correct, but sometime it gets wrong information and many times it returns null values because the result comes is dynamic not fixed.
so anybody suggest me how to make this dynamic and check inside is country city pincode and state are available in any of the array index from result ....
below is my code...
$fromlat = $this->request->data['Order']['from_lat'];
$fromlong = $this->request->data['Order']['from_long'];
$geocode = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng='.$fromlat.','.$fromlong.'&sensor=false');
$json = json_decode($geocode);
//print_r($geocode);
$country = $json->{'results'}[1]->{'address_components'}[3]->{'long_name'};
$state = $json->{'results'}[1]->{'address_components'}[2]->{'long_name'};
$city = $json->{'results'}[1]->{'address_components'}[1]->{'long_name'};
$locality = $json->{'results'}[1]->{'address_components'}[0]->{'long_name'};
$pincode = $json->{'results'}[1]->{'address_components'}[4]->{'long_name'};
echo $locality."</br>".$country."</br>".$state."</br>".$city."</br>".$pincode;
i need to check types in address components like below in result forloop and if available then display result.
types = country = country name;
types = administrative_area_level_1 = state name ;
types = administrative_area_level_2 = city name ;
types = postal_code = pincode ;
below is my result array...
stdClass Object
(
[results] => Array
(
[0] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Kurkheda - Wadsa - Bramhapuri - Nagpur Highway
[short_name] => MH MSH 9
[types] => Array
(
[0] => route
)
)
[1] => stdClass Object
(
[long_name] => Nagpur
[short_name] => Nagpur
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[2] => stdClass Object
(
[long_name] => Maharashtra
[short_name] => MH
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[3] => stdClass Object
(
[long_name] => India
[short_name] => IN
[types] => Array
(
[0] => country
[1] => political
)
)
[4] => stdClass Object
(
[long_name] => 441204
[short_name] => 441204
[types] => Array
(
[0] => postal_code
)
)
)
[formatted_address] => Kurkheda - Wadsa - Bramhapuri - Nagpur Hwy, Maharashtra 441204, India
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 21.0633475
[lng] => 79.1652473
)
[southwest] => stdClass Object
(
[lat] => 21.0599518
[lng] => 79.1646723
)
)
[location] => stdClass Object
(
[lat] => 21.0616013
[lng] => 79.1647236
)
[location_type] => GEOMETRIC_CENTER
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 21.0633475
[lng] => 79.166308780291
)
[southwest] => stdClass Object
(
[lat] => 21.0599518
[lng] => 79.163610819708
)
)
)
[place_id] => ChIJj5wNX6O51DsRz53GLG9aZRM
[types] => Array
(
[0] => route
)
)
[1] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Kalamana
[short_name] => Kalamana
[types] => Array
(
[0] => locality
[1] => political
)
)
[1] => stdClass Object
(
[long_name] => Nagpur
[short_name] => Nagpur
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[2] => stdClass Object
(
[long_name] => Maharashtra
[short_name] => MH
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[3] => stdClass Object
(
[long_name] => India
[short_name] => IN
[types] => Array
(
[0] => country
[1] => political
)
)
[4] => stdClass Object
(
[long_name] => 441204
[short_name] => 441204
[types] => Array
(
[0] => postal_code
)
)
)
[formatted_address] => Kalamana, Maharashtra 441204, India
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 21.0628156
[lng] => 79.164412
)
[southwest] => stdClass Object
(
[lat] => 21.0589309
[lng] => 79.1617083
)
)
[location] => stdClass Object
(
[lat] => 21.0605174
[lng] => 79.1629662
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 21.0628156
[lng] => 79.164412
)
[southwest] => stdClass Object
(
[lat] => 21.0589309
[lng] => 79.1617083
)
)
)
[place_id] => ChIJ2yhznKO51DsRGZWqNrtKBD4
[types] => Array
(
[0] => locality
[1] => political
)
)
[2] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => 441204
[short_name] => 441204
[types] => Array
(
[0] => postal_code
)
)
[1] => stdClass Object
(
[long_name] => Nagpur
[short_name] => Nagpur
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[2] => stdClass Object
(
[long_name] => Maharashtra
[short_name] => MH
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[3] => stdClass Object
(
[long_name] => India
[short_name] => IN
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Maharashtra 441204, India
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 21.139709
[lng] => 79.3452018
)
[southwest] => stdClass Object
(
[lat] => 20.8714046
[lng] => 79.0962536
)
)
[location] => stdClass Object
(
[lat] => 20.9903768
[lng] => 79.2451149
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 21.139709
[lng] => 79.3452018
)
[southwest] => stdClass Object
(
[lat] => 20.8714046
[lng] => 79.0962536
)
)
)
[place_id] => ChIJKTHfbpOw1DsRGwYyMATAfU4
[types] => Array
(
[0] => postal_code
)
)
[3] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Nagpur
[short_name] => Nagpur
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[1] => stdClass Object
(
[long_name] => Maharashtra
[short_name] => MH
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[2] => stdClass Object
(
[long_name] => India
[short_name] => IN
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Nagpur, Maharashtra, India
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 21.713785
[lng] => 79.65179
)
[southwest] => stdClass Object
(
[lat] => 20.5841799
[lng] => 78.2515599
)
)
[location] => stdClass Object
(
[lat] => 21.3170198
[lng] => 79.1999949
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 21.713785
[lng] => 79.65179
)
[southwest] => stdClass Object
(
[lat] => 20.5841799
[lng] => 78.2515599
)
)
)
[place_id] => ChIJ691n-cTA1DsRh3HGEikxZ2E
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[4] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Maharashtra
[short_name] => MH
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[1] => stdClass Object
(
[long_name] => India
[short_name] => IN
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Maharashtra, India
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 22.027909
[lng] => 80.890924
)
[southwest] => stdClass Object
(
[lat] => 15.602412
[lng] => 72.6593629
)
)
[location] => stdClass Object
(
[lat] => 19.7514798
[lng] => 75.7138884
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 22.027909
[lng] => 80.890924
)
[southwest] => stdClass Object
(
[lat] => 15.602412
[lng] => 72.6593629
)
)
)
[place_id] => ChIJ-dacnB7EzzsRtk_gS5IiLxs
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[5] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => India
[short_name] => IN
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => India
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 35.5087008
[lng] => 97.395561
)
[southwest] => stdClass Object
(
[lat] => 6.7535159
[lng] => 68.1623859
)
)
[location] => stdClass Object
(
[lat] => 20.593684
[lng] => 78.96288
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 35.5087008
[lng] => 97.395561
)
[southwest] => stdClass Object
(
[lat] => 6.7535159
[lng] => 68.1633666
)
)
)
[place_id] => ChIJkbeSa_BfYzARphNChaFPjNc
[types] => Array
(
[0] => country
[1] => political
)
)
)
[status] => OK
)
Proper way to extract values of address components is done as following :
if (results[0]) {
$("input[name=lat]").val(results[0].geometry.location.lat());
$("input[name=lng]").val(results[0].geometry.location.lng());
var addressArr = [];
$.each(results[0].address_components, function (key, val) {
if (!$.inArray("country", results[0].address_components[key].types)) {
addressArr['country'] = results[0].address_components[key].long_name;
}
if (!$.inArray("administrative_area_level_1", results[0].address_components[key].types)) {
addressArr['state'] = results[0].address_components[key].long_name;
}
if (!$.inArray("administrative_area_level_2", results[0].address_components[key].types)) {
addressArr['city'] = results[0].address_components[key].long_name;
}
});
console.log(addressArr);
}
}
I have some similar code that is known to work. Basically it can return a results array if there are more than one results possible or just an object if only one result is found. My use-case is slightly different, but hopefully it helps. Try this:
$ch = curl_init();
$geoCodeUrl = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $zip . ',+United+States&key=' . $googleApiKey;
curl_setopt($ch,CURLOPT_URL, $geoCodeUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$result = curl_exec($ch);
curl_close($ch);
$GeoCode = json_decode($result);
$GeoLocator = new \stdClass();
if( isset($GeoCode->results[0]) ){
$GeoLocator->lat = $GeoCode->results[0]->geometry->location->lat;
$GeoLocator->lon = $GeoCode->results[0]->geometry->location->lng;
foreach($GeoCode->results[0]->address_components as $comp){
if( in_array('locality',$comp->types) ){
$GeoLocator->city = trim($comp->short_name);
}
else if( in_array('administrative_area_level_1',$comp->types) ){
$GeoLocator->state = strtoupper(trim(preg_replace('/\d/', '', $comp->short_name)));
}
}
}
else if( isset($GeoCode->results) && isset($GeoCode->results->geometry) ){
$GeoLocator->lat = $GeoCode->results->geometry->location->lat;
$GeoLocator->lon = $GeoCode->results->geometry->location->lng;
foreach($GeoCode->results->address_components as $comp){
if( in_array('locality',$comp->types) ){
$GeoLocator->city = trim($comp->short_name);
}
else if( in_array('administrative_area_level_1',$comp->types) ){
$GeoLocator->state = strtoupper(trim(preg_replace('/\d/', '', $comp->short_name)));
}
}
}

json object to array convert using php

I want to echo value in the json array one by one when i want
<?php
function get_web_page($url) {
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false // don't return headers
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
$response = get_web_page("http://maps.googleapis.com/maps/api/geocode/json?address=colombo");
$resArr = array();
$resArr = json_decode($response);
echo "<pre>";
print_r($resArr);
echo "</pre>";
echo "<br>";
echo "<br>";
;
?>
This is the current result in the browser above code
stdClass Object
(
[results] => Array
(
[0] => stdClass Object
(
[address_components] => Array
(
[0] => stdClass Object
(
[long_name] => Colombo
[short_name] => Colombo
[types] => Array
(
[0] => locality
[1] => political
)
)
[1] => stdClass Object
(
[long_name] => Colombo
[short_name] => Colombo
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[2] => stdClass Object
(
[long_name] => Western Province
[short_name] => WP
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[3] => stdClass Object
(
[long_name] => Sri Lanka
[short_name] => LK
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Colombo, Sri Lanka
[geometry] => stdClass Object
(
[bounds] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 6.9805844
[lng] => 79.8900852
)
[southwest] => stdClass Object
(
[lat] => 6.8625113
[lng] => 79.8225192
)
)
[location] => stdClass Object
(
[lat] => 6.9270786
[lng] => 79.861243
)
[location_type] => APPROXIMATE
[viewport] => stdClass Object
(
[northeast] => stdClass Object
(
[lat] => 6.9805844
[lng] => 79.8900852
)
[southwest] => stdClass Object
(
[lat] => 6.8625113
[lng] => 79.8225192
)
)
)
[place_id] => ChIJA3B6D9FT4joRjYPTMk0uCzI
[types] => Array
(
[0] => locality
[1] => political
)
)
)
[status] => OK
)
I want to echo value by value
try it with:
$resArr = json_decode($response, true);
It will convert it into associative array format.
For more detail have a look at JSON Decode PHP

Postcode of visitor location PHP

On my page I have a number of registered users, each user has a postcode stored in their row in my table.
I'm wondering if its possible and if so how to get the postcode of my website visitors and then show them the nearest users going of the data in my table?
You can use HTML 5 Geolocation to ask them to provide their location to you. Then you could lookup what the nearest postal code is based on their longitude/latitude.
You can get free postal/zip data with long/lat for North America here:
http://geocoder.ca/?freedata=1
If you can determine the coordinates of the visiting user in an accurate way you could use the google reverse geocoding API to translate the coordinates to an address and use the zipcode from that address.
Determining accurate coordinates of a visitor could prove difficult though. You'll have to rely on a GeoLocation api like http://www.maxmind.com/app/php or do an implementation of the HTML5 GeoLocation API.
You need to populate latitude/longitude for each record, then use Google Maps to find out nearest users, I believe following links will help you out.
Get latitude and longitude based on location name with Google Autocomplete API
Google Maps Api v3 - find nearest markers
Interesting, building on what others have said, perhaps this example will help ;)
<?php
//example a google IP
$user_info = get_ip_info('74.125.224.72');
$google_info = get_google_data($user_info['latitude'],$user_info['longitude']);
$user = array_merge($user_info,$google_info);
//See below for result
print_r($user);
function get_google_data($long,$lat){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://maps.googleapis.com/maps/api/geocode/json?latlng='.$long.','.$lat.'&sensor=true');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data,true);
}
function get_ip_info($ip = NULL){
if(empty($ip)) $ip = $_SERVER['REMOTE_ADDR'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://www.ipaddresslocation.org/ip-address-locator.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,array('ip'=>$ip));
$data = curl_exec($ch);
curl_close($ch);
preg_match_all('/<i>([a-z\s]+)\:<\/i>\s+<b>(.*)<\/b>/im',$data,$matches,PREG_SET_ORDER);
if(count($matches)==0)return false;
$return = array();
$labels = array(
'Hostname' => 'host',
'IP Country' => 'country',
'IP Country Code' => 'country_code',
'IP Continent' => 'continent',
'IP Region' => 'region',
'IP Latitude' => 'latitude',
'IP Longitude' => 'longitude',
'Organization' => 'organization',
'ISP Provider' => 'isp');
foreach($matches as $info){
if(isset($info[2]) && !is_null($labels[$info[1]])){
$return[$labels[$info[1]]]=$info[2];
}
}
return (count($return))?$return:false;
}
/**
* Result:
*
*
* Array
(
[host] => nuq04s07-in-f8.1e100.net
[country] => United States
[country_code] => USA
[continent] => North America
[region] => California
[latitude] => 37.4192
[longitude] => -122.0574
[organization] => Google
[isp] => Google
[results] => Array
(
[0] => Array
(
[address_components] => Array
(
[0] => Array
(
[long_name] => Sevryns Rd
[short_name] => Sevryns Rd
[types] => Array
(
[0] => route
)
)
[1] => Array
(
[long_name] => Mountain View
[short_name] => Mountain View
[types] => Array
(
[0] => locality
[1] => political
)
)
[2] => Array
(
[long_name] => Santa Clara
[short_name] => Santa Clara
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[3] => Array
(
[long_name] => California
[short_name] => CA
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[4] => Array
(
[long_name] => United States
[short_name] => US
[types] => Array
(
[0] => country
[1] => political
)
)
[5] => Array
(
[long_name] => 94043
[short_name] => 94043
[types] => Array
(
[0] => postal_code
)
)
)
[formatted_address] => Sevryns Rd, Mountain View, CA 94043, USA
[geometry] => Array
(
[bounds] => Array
(
[northeast] => Array
(
[lat] => 37.4197948
[lng] => -122.0577433
)
[southwest] => Array
(
[lat] => 37.4175854
[lng] => -122.0590077
)
)
[location] => Array
(
[lat] => 37.4187254
[lng] => -122.0583059
)
[location_type] => APPROXIMATE
[viewport] => Array
(
[northeast] => Array
(
[lat] => 37.420039080292
[lng] => -122.05702651971
)
[southwest] => Array
(
[lat] => 37.417341119709
[lng] => -122.05972448029
)
)
)
[types] => Array
(
[0] => route
)
)
[1] => Array
(
[address_components] => Array
(
[0] => Array
(
[long_name] => Moffett Federal Airfield
[short_name] => Moffett Federal Airfield
[types] => Array
(
[0] => establishment
)
)
[1] => Array
(
[long_name] => Cummins Ave
[short_name] => Cummins Ave
[types] => Array
(
[0] => route
)
)
[2] => Array
(
[long_name] => Mountain View
[short_name] => Mountain View
[types] => Array
(
[0] => locality
[1] => political
)
)
[3] => Array
(
[long_name] => Santa Clara
[short_name] => Santa Clara
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[4] => Array
(
[long_name] => California
[short_name] => CA
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[5] => Array
(
[long_name] => United States
[short_name] => US
[types] => Array
(
[0] => country
[1] => political
)
)
[6] => Array
(
[long_name] => 94043
[short_name] => 94043
[types] => Array
(
[0] => postal_code
)
)
)
[formatted_address] => Moffett Federal Airfield (NUQ), Cummins Ave, Mountain View, CA 94043, USA
[geometry] => Array
(
[bounds] => Array
(
[northeast] => Array
(
[lat] => 37.4298225
[lng] => -122.0375869
)
[southwest] => Array
(
[lat] => 37.4019577
[lng] => -122.0589996
)
)
[location] => Array
(
[lat] => 37.4199527
[lng] => -122.0584702
)
[location_type] => APPROXIMATE
[viewport] => Array
(
[northeast] => Array
(
[lat] => 37.4298225
[lng] => -122.0375869
)
[southwest] => Array
(
[lat] => 37.4019577
[lng] => -122.0589996
)
)
)
[types] => Array
(
[0] => airport
[1] => transit_station
[2] => establishment
)
)
[2] => Array
(
[address_components] => Array
(
[0] => Array
(
[long_name] => 94043
[short_name] => 94043
[types] => Array
(
[0] => postal_code
)
)
[1] => Array
(
[long_name] => Mountain View
[short_name] => Mountain View
[types] => Array
(
[0] => locality
[1] => political
)
)
[2] => Array
(
[long_name] => California
[short_name] => CA
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[3] => Array
(
[long_name] => United States
[short_name] => US
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Mountain View, CA 94043, USA
[geometry] => Array
(
[bounds] => Array
(
[northeast] => Array
(
[lat] => 37.464087
[lng] => -122.03599
)
[southwest] => Array
(
[lat] => 37.3857439
[lng] => -122.10842
)
)
[location] => Array
(
[lat] => 37.428434
[lng] => -122.0723816
)
[location_type] => APPROXIMATE
[viewport] => Array
(
[northeast] => Array
(
[lat] => 37.464087
[lng] => -122.03599
)
[southwest] => Array
(
[lat] => 37.3857439
[lng] => -122.10842
)
)
)
[types] => Array
(
[0] => postal_code
)
)
[3] => Array
(
[address_components] => Array
(
[0] => Array
(
[long_name] => Santa Clara
[short_name] => Santa Clara
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[1] => Array
(
[long_name] => California
[short_name] => CA
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[2] => Array
(
[long_name] => United States
[short_name] => US
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => Santa Clara, CA, USA
[geometry] => Array
(
[bounds] => Array
(
[northeast] => Array
(
[lat] => 37.484637
[lng] => -121.208178
)
[southwest] => Array
(
[lat] => 36.894155
[lng] => -122.202476
)
)
[location] => Array
(
[lat] => 37.2938907
[lng] => -121.7195459
)
[location_type] => APPROXIMATE
[viewport] => Array
(
[northeast] => Array
(
[lat] => 37.484637
[lng] => -121.208178
)
[southwest] => Array
(
[lat] => 36.894155
[lng] => -122.202476
)
)
)
[types] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[4] => Array
(
[address_components] => Array
(
[0] => Array
(
[long_name] => California
[short_name] => CA
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[1] => Array
(
[long_name] => United States
[short_name] => US
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => California, USA
[geometry] => Array
(
[bounds] => Array
(
[northeast] => Array
(
[lat] => 42.0095169
[lng] => -114.131211
)
[southwest] => Array
(
[lat] => 32.5342071
[lng] => -124.4096195
)
)
[location] => Array
(
[lat] => 36.778261
[lng] => -119.4179324
)
[location_type] => APPROXIMATE
[viewport] => Array
(
[northeast] => Array
(
[lat] => 42.0095169
[lng] => -114.131211
)
[southwest] => Array
(
[lat] => 32.5342071
[lng] => -124.4096195
)
)
)
[types] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[5] => Array
(
[address_components] => Array
(
[0] => Array
(
[long_name] => United States
[short_name] => US
[types] => Array
(
[0] => country
[1] => political
)
)
)
[formatted_address] => United States
[geometry] => Array
(
[bounds] => Array
(
[northeast] => Array
(
[lat] => 90
[lng] => 180
)
[southwest] => Array
(
[lat] => -90
[lng] => -180
)
)
[location] => Array
(
[lat] => 37.09024
[lng] => -95.712891
)
[location_type] => APPROXIMATE
[viewport] => Array
(
[northeast] => Array
(
[lat] => 49.38
[lng] => -66.94
)
[southwest] => Array
(
[lat] => 25.82
[lng] => -124.39
)
)
)
[types] => Array
(
[0] => country
[1] => political
)
)
)
[status] => OK
)
*/
?>

Iterate through SimpleXMLElement to retrieve postal code value

I am trying to extract the postal code from the Google Geocode v3 API XML Response. The difficulty I am having is that sometimes the postal_code value is contained in the 6th address_element and sometimes in the 7th. Here is the XML response that I am working with and in this sample response you can see that the postal_code is the 6th element of the address_component array:
SimpleXMLElement Object
(
[status] => OK
[result] => Array
(
[0] => SimpleXMLElement Object
(
[type] => street_address
[formatted_address] => 177 Church St, Toronto, ON M5C 2G5, Canada
[address_component] => Array
(
[0] => SimpleXMLElement Object
(
[long_name] => 177
[short_name] => 177
[type] => street_number
)
[1] => SimpleXMLElement Object
(
[long_name] => Church St
[short_name] => Church St
[type] => route
)
[2] => SimpleXMLElement Object
(
[long_name] => Toronto
[short_name] => Toronto
[type] => Array
(
[0] => locality
[1] => political
)
)
[3] => SimpleXMLElement Object
(
[long_name] => Toronto
[short_name] => Toronto
[type] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[4] => SimpleXMLElement Object
(
[long_name] => Ontario
[short_name] => ON
[type] => Array
(
[0] => administrative_area_level_1
[1] => political
)
)
[5] => SimpleXMLElement Object
(
[long_name] => Canada
[short_name] => CA
[type] => Array
(
[0] => country
[1] => political
)
)
[6] => SimpleXMLElement Object
(
[long_name] => M5C 2G5
[short_name] => M5C 2G5
[type] => postal_code
)
)
[geometry] => SimpleXMLElement Object
(
[location] => SimpleXMLElement Object
(
[lat] => 43.6547363
[lng] => -79.3763746
)
[location_type] => RANGE_INTERPOLATED
[viewport] => SimpleXMLElement Object
(
[southwest] => SimpleXMLElement Object
(
[lat] => 43.6533849
[lng] => -79.3777345
)
[northeast] => SimpleXMLElement Object
(
[lat] => 43.6560829
[lng] => -79.3750365
)
)
[bounds] => SimpleXMLElement Object
(
[southwest] => SimpleXMLElement Object
(
[lat] => 43.6547315
[lng] => -79.3763964
)
[northeast] => SimpleXMLElement Object
(
[lat] => 43.6547363
[lng] => -79.3763746
)
)
)
)
I haven't tried this, but I think it should work.
$address = $array->result[0]->address_component;
$postal_code = '';
foreach($address as $adr){
if($adr->type == 'postal_code'){
$postal_code = $adr->long_name;
}
}

Categories