/**
  * Try to fill in coordinates and other fields of a location from a textual
  * location search.
  *
  * Multiple geocoding services may be used. Google services are only used
  * if the default map provider is Google.
  * 
  * @since 1.3
  *
  * @param mixed $query The search string.
  * @param array $location The location array to geocode, modified.
  * @param string $language 
  * @return bool Whether a lookup succeeded.
  */
 public static function geocode($query, &$location, $language = '')
 {
     global $geo_mashup_options;
     if (empty($location)) {
         $location = self::blank_location();
     } else {
         if (!is_array($location) and !is_object($location)) {
             return false;
         }
     }
     $status = false;
     if (!class_exists('GeoMashupHttpGeocoder')) {
         include_once path_join(GEO_MASHUP_DIR_PATH, 'geo-mashup-geocoders.php');
     }
     // Try GeoCoding services (google, nominatim, geonames) until one gives an answer
     $results = array();
     if ('google' == substr($geo_mashup_options->get('overall', 'map_api'), 0, 6)) {
         // Only try the google service if a google API is selected as the default
         $google_geocoder = new GeoMashupGoogleGeocoder(array('language' => $language));
         $results = $google_geocoder->geocode($query);
     }
     if (is_wp_error($results) or empty($results)) {
         self::$geocode_error = $results;
         $nominatim_geocoder = new GeoMashupNominatimGeocoder(array('language' => $language));
         $results = $nominatim_geocoder->geocode($query);
     }
     if (is_wp_error($results) or empty($results)) {
         self::$geocode_error = $results;
         $geonames_geocoder = new GeoMashupGeonamesGeocoder(array('language' => $language));
         $results = $geonames_geocoder->geocode($query);
     }
     if (is_wp_error($results) or empty($results)) {
         self::$geocode_error = $results;
     } else {
         self::fill_empty_location_fields($location, $results[0]);
         $status = true;
     }
     return $status;
 }