--- google.inc.orig 2009-09-20 22:27:27.000000000 -0700 +++ google.inc 2009-09-21 15:45:39.000000000 -0700 @@ -8,78 +8,53 @@ /** * Return the list of ISO3166 codes supported by this geocoder. - * Coverage list: http://gmaps-samples.googlecode.com/svn/trunk/mapcoverage_filtered.html - * Possibly in the future, allow to autogenerate this by pulling down and parsing the spreadsheet? + * Coverage list: http://gmaps-samples.googlecode.com/svn/trunk/mapcoverage_filtered.html + * Coverage list feed: http://spreadsheets.google.com/feeds/list/p9pdwsai2hDMsLkXsoM05KQ/default/public/values */ function google_geocode_country_list() { - return array( - /* Afghanistan */ 'af', - /* Albania */ 'al', - /* Argentina */ 'ar', - /* Australia */ 'au', - /* Austria */ 'at', - /* Belarus */ 'by', - /* Belgium */ 'be', - /* Bosnia and Herzegovina */ 'ba', - /* Brazil */ 'br', - /* Bulgaria */ 'bg', - /* Canada */ 'ca', - /* Chile */ 'cl', - /* China */ 'cn', - /* Croatia */ 'hr', - /* Czech Republic */ 'cz', - /* Denmark */ 'dk', - /* Ecuador */ 'ec', - /* El Salvador */ 'sv', - /* Estonia */ 'ee', - /* Finland */ 'fi', - /* France */ 'fr', - /* Germany */ 'de', - /* Greece */ 'gr', - /* Hong Kong */ 'hk', - /* Hungary */ 'hu', - /* India */ 'in', - /* Ireland */ 'ie', - /* Italy */ 'it', - /* Japan */ 'jp', - /* Kenya */ 'ke', - /* Latvia */ 'lv', - /* Lebanon */ 'lb', - /* Liechtenstein */ 'li', - /* Lithuania */ 'lt', - /* Luxembourg */ 'lu', - /* Macau */ 'mo', - /* Macedonia */ 'mk', - /* Malaysia */ 'my', - /* Mexico */ 'mx', - /* Moldova */ 'md', - /* Montenegro */ 'me', - /* Netherlands */ 'nl', - /* New Zealand */ 'nz', - /* Nicaragua */ 'ni', - /* Norway */ 'no', - /* Panama */ 'pa', - /* Poland */ 'pl', - /* Portugal */ 'pt', - /* Romania */ 'ro', - /* Russia */ 'ru', - /* San Marino */ 'sm', - /* Serbia */ 'rs', - /* Singapore */ 'sg', - /* Slovakia */ 'sk', - /* Slovenia */ 'si', - /* South Korea */ 'kr', - /* Spain */ 'es', - /* Sweden */ 'se', - /* Switzerland */ 'ch', - /* Taiwan */ 'tw', - /* Thailand */ 'th', - /* Turkey */ 'tr', - /* Ukraine */ 'ua', - /* United Kingdom */ 'uk', - /* United States */ 'us', - /* Uruguay */ 'uy', - ); + + // include and use the Feed Parser to get the google data and create an array from the feed + include('FeedParser.php'); + $Parser = new FeedParser(); + $Parser->parse('http://spreadsheets.google.com/feeds/list/p9pdwsai2hDMsLkXsoM05KQ/default/public/values'); + $parsedArray = $Parser->getItems(); + + // Loop though google data and find all valid entries and make new array + $regionclean = array(); + $regionkey = -1; + foreach($parsedArray as $region) { + if(stristr($region['GSX:GEOCODING'],"Yes")) { + $regionkey = $regionkey+1; + $regionclean[$regionkey] = htmlentities($region['GSX:COUNTRYREGION']); + } + } + + // Get the countries list and clean it up so that names will match to google. + // The regex removes parenthetical items so that both of the "Congo" entries and the "Coco Islands" work. + // The $countries_fixes overwrites values in the Drupal API countries list with values that will match to google's entries. + // "Sao Tome and Principe" are non-accented in the Drupal API so the entry here is to match the htmlentities() fix in the foreach loop below. + // I know that it looks weird, but that's the way the feed parser and htmlentities() spit it out so... + // Note: it may be neccessary to adjust/add to the fixes list in the future if google adds countries that don't match the Drupal API list for whatever reason. + $countries = location_get_iso3166_list(); + $regex = "#[ (].*[)]#e"; + $cntryclean = preg_replace($regex,"",$countries); + $countriesfixes = array_merge($cntryclean,array("tl"=>"Timor-Leste", + "hk"=>"China", + "mo"=>"China", + "pn"=>"Pitcairn Islands", + "wf"=>"Wallis Futuna", + "st"=>"São Tomé and Príncipe" + )); + + + + // Compare new google array values to fixed country names values, return matches with keys abbreviations as keys + $googlematched = array_intersect($countriesfixes, $regionclean); + + // Compare new keys to original Drupal API and return the array with the original name values + $fixedkeys = array_intersect_key($countries, $googlematched); + + return array_keys($fixedkeys); } /**