$regionName,'lat' => 0,'lon' => 0); $r = new HttpRequest('//maps.googleapis.com/maps/api/geocode/json', HttpRequest::METH_GET); $r->addQueryData(array('address' => urlencode($regionName), 'sensor' => 'false')); $r->send(); if ($r->getResponseCode() == 200) { $resp = json_decode($r->getResponseBody()); if (count($resp->results) == 0) return null; else { return array( 'long_name' => $resp->results[0]->address_components[0]->long_name, 'lat' => $resp->results[0]->geometry->location->lat, 'lon' => $resp->results[0]->geometry->location->lng); } } else { return null; } } //returns array with all members, or subarrays in array that match the key and value function search($array, $key, $value){ $results = array(); if (is_array($array)) { if (isset($array[$key]) && $array[$key] == $value) $results[] = $array; foreach ($array as $subarray) $results = array_merge($results, search($subarray, $key, $value)); } return $results; } function in_array_r($needle, $haystack) { $found = false; foreach ($haystack as $item) { if ($item === $needle) { $found = true; break; } elseif (is_array($item)) { $found = in_array_r($needle, $item); if($found) { break; } } } return $found; } function unique($array, $key){ $results = array(); if(is_array($array)) { foreach($array as $elem) if(isset($elem[$key]) && !in_array($elem[$key],$results)) array_push($results,$elem[$key]); } return $results; } function toxml($array,$outerkey,$tabs) { $xml = ""; foreach($array as $key=>$value) { if(is_array($value)) { if(is_numeric($key)) { $xml .= gt($tabs)."<".htmlspecialchars($outerkey).">".toxml($value,$outerkey,$tabs+1).gt($tabs).""; } else { if(isAssoc($value)) { $xml .= gt($tabs)."<".htmlspecialchars($key).">".toxml($value,$key,$tabs+1).gt($tabs).""; } else { $xml .= toxml($value,$key,$tabs); } } } else { $xml .= gt($tabs)."<".htmlspecialchars($key).">".htmlspecialchars($value).""; } } return $xml; } function isAssoc($arr) { return array_keys($arr) !== range(0, count($arr) - 1); } function gt($num) { $t = "\n"; while($num--) $t .= "\t"; return $t; } function monthName($monthNum) { switch($monthNum) { case 1: return 'January'; case 2: return 'February'; case 3: return 'March'; case 4: return 'April'; case 5: return 'May'; case 6: return 'June'; case 7: return 'July'; case 8: return 'August'; case 9: return 'September'; case 10: return 'October'; case 11: return 'November'; case 12: return 'December'; } } ?>