public function IpGeoLocGlobal::flattenGoogleAddress in IP Geolocation Views & Maps 8
Fleshes out the $ip_geoloc_address array.
This is based on the additional data provided in the $google_address array. This may involve tweaking of the 'latitude' and 'longitude' entries so that they remain consistent with the street address components.
Parameters
array $google_address: Array of address components as returned by Google service.
array $ip_geoloc_address: The $google_address in flattened form.
Return value
bool TRUE, unless google_address or ip_geoloc_address are empty
File
- src/
Services/ IpGeoLocGlobal.php, line 280
Class
- IpGeoLocGlobal
- Class IpGeoLocGlobal.
Namespace
Drupal\ip_geoloc\ServicesCode
public function flattenGoogleAddress(array $google_address, array &$ip_geoloc_address) {
if (is_array($google_address) && is_array($google_address['address_components']) && is_array($ip_geoloc_address)) {
$ip_geoloc_address['provider'] = 'google';
foreach ($google_address['address_components'] as $component) {
$long_name = $component['long_name'];
if (!empty($long_name)) {
$type = $component['types'][0];
$ip_geoloc_address[$type] = $long_name;
if ($type == 'country' && !empty($component['short_name'])) {
$ip_geoloc_address['country_code'] = $component['short_name'];
}
}
}
$ip_geoloc_address['formatted_address'] = $google_address['formatted_address'];
// The following may be slightly different from the original lat,long passed
// into ip_geoloc_reverse_geocode().
$ip_geoloc_address['latitude'] = $google_address['geometry']['location']['lat'];
$ip_geoloc_address['longitude'] = $google_address['geometry']['location']['lng'];
return TRUE;
}
return FALSE;
}