You are here

function _google_geocode_get_components in Location 7.3

Same name and namespace in other branches
  1. 6.3 geocoding/google.inc \_google_geocode_get_components()

Gets a components string to pass to the google geocode API.

This is required to get more accurate results because sometimes when passing in a small piece of information, like a country code only, it could also match a different part of an address for another country as the highest match.

See https://developers.google.com/maps/documentation/geocoding/#ComponentFil... for details.

Parameters

array $location: A location array.

Return value

string A components string formatted as per the docs page linked to above.

1 call to _google_geocode_get_components()
google_geocode_location in geocoding/google.inc
Perform a geocode on a location array.

File

geocoding/google.inc, line 229
Google geocoder.

Code

function _google_geocode_get_components($location = array()) {

  // Check if its a valid address.
  if (empty($location)) {
    return '';
  }
  $components = array();
  if (!empty($location['city'])) {
    $components[] = 'locality:' . $location['city'];
  }
  if (!empty($location['province_name'])) {
    $components[] = 'administrative_area:' . $location['province_name'];
  }
  if (!empty($location['postal_code'])) {
    $components[] = 'postal_code:' . $location['postal_code'];
  }
  if (!empty($location['country'])) {
    $components[] = 'country:' . $location['country'];
  }
  return implode('|', $components);
}