Since I found a solution to my problem I post here also the code solving the problem above from the code posted. I could get the value of city, state, country in first iteration so it was performing unnecessary iterations and therefore getting results from US as I saw in the json returned. Now I will also parse the data to make junk data such as "in my world etc" excluded and I will be able to group them by country.
<?php
// Get STATE from Google GeoData
function reverse_geocode($address) {
$address = str_replace(" ", "+", "$address");
$url = "http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false";
$result = file_get_contents("$url");
$json = json_decode($result);
foreach ($json->results as $k => $result)
{
if ($k == 0) {
foreach($result->address_components as $addressPart) {
if ((in_array('locality', $addressPart->types)) && (in_array('political', $addressPart->types))) {
$city = $addressPart->long_name;
} else if((in_array('administrative_area_level_1', $addressPart->types)) && (in_array('political', $addressPart->types))) {
$state = $addressPart->long_name;
}
else if((in_array('country', $addressPart->types)) && (in_array('political', $addressPart->types))) {
$country = $addressPart->long_name;
}
}
} else {
break; //Will comes out of loop directly after getting result.
}
}
if($country != '')
$address = $country;
// return $address;
return "$country";
}
// Usage: In my case, I needed to return the State and Country of an address
$myLocation = reverse_geocode("Athens");
echo "$myLocation";
?>
@JaredFarrish thanks for the help you provided in the first part :)