And when you heal my broken wings,
yes, you heal my everything...
You tell me to live.

Searching Google Geocoder Information

December 9th, 2009 by FunnyLookinHat

Before I forget I just want to post this bit of code - took me way too long to figure this out - it’s a long story. In any case, if you’re ever using PHP to get google geocoder information and it’s stored in a JSON Object - you probably realized it’s hard to find a particular key at times because of varying levels of data returned by google…  in any case, you can use this function to quickly and easily get the first result for a matching key.

function getPlaceValue($object, $lookingFor) {
foreach($object as $key=>$obj) {
if(strcmp($key,$lookingFor)==0) {
return $obj;
} else if(is_object($obj)) {
$ok = getPlaceValue($obj,$lookingFor);
if($ok) {
return $ok;
}
}
}
return false;
}

That should work for any nested object as well…  so enjoy!

Posted in Uncategorized

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

About FunnyLookinHat’s /etc/var/self/log.txt

All content is copyright David Overcash. You may use whatever you find on this site, but please cite David Overcash @ http://www.funnylookinhat.com.

Visitors:

wordpress stats 
plugin

Site Statistics