webempoweredchurch/wec_map — Issue #16: Make Google-Request-URL more configurable  
Author: ckoehler
Created: 2011-11-30 03:45:59+00:00
State: open

I had several address-items that google didn't resolve properly. These addresses contained umlauts in an iso8859-1 environment. Google needs the address information in utf-8, but the Geocode-class doesn't convert to utf-8. Besides for German addresses a different order of the address-fields is more common and leads to much better results. I've patched the lookup-function as follows:

tx_wecmap_geocode_google::lookup($street, $city, $state, $zip, $country, $key='') {
...
// $lookupstr = trim($street.' '.$city.', '.$state.' '.$zip.', '.$country);
$lookupstr = utf8_encode( trim($street.','.$zip.' '.$city.','.$country) );
...
}

See also http://webempoweredchurch.com/support/community/forum/single_thread/ministry-tools/map-extension/goecoding-problems-and-danish-characters/
from where I got the idea to patch the string.

It would be great if the $lookupstr could be set-up using some kind of TS. That would allow an easy upgrade process without patching the local installation.

Example to illustrate:

plugin.tx_wecmap_geocode_google {
lookupstr = ###street###,###zip### ###city###,###country###
}

These markers could be replaced by the according variable-names and the string be evaluated by PHP. Feel free to change if other syntax of TS is more suitable. The utf8-conversion should be done automatically if necessary.

http://svn.webempoweredchurch.org/attachments/131/class.tx_wecmap_geocode_google.php

This should work:
if ( t3lib_extMgm.isLoaded('static_info_tables') )
{
// format address for Google search based on local address-format for given $country

// load and init Static Info Tables
require_once(t3lib_extMgm::extPath('static_info_tables').'pi1/class.tx_staticinfotables_pi1.php');
$this->staticInfoObj = &t3lib_div::getUserObj('&tx_staticinfotables_pi1');
if ($this->staticInfoObj->needsInit()){
$this->staticInfoObj->init();
}

// convert $country to ISO3
$countryCodeType = tx_staticinfotables_div::isoCodeType($country);
if ($countryCodeType == 'nr') {
$countryArray = tx_staticinfotables_div::fetchCountries('', '', '', $country);
} elseif ($countryCodeType == '2') {
$countryArray = tx_staticinfotables_div::fetchCountries('', $country, '', '');
} elseif ($countryCodeType == '3') {
$countryArray = tx_staticinfotables_div::fetchCountries('', '', $country, '');
} else {
$countryArray = tx_staticinfotables_div::fetchCountries($country, '', '', '');
}

if(TYPO3_DLOG) {
t3lib_div::devLog('Google V3: countryArray for '.$country, 'wec_map_geocode', -1, $countryArray);
}

if ( is_array( $countryArray ) )
$country = $countryArray[0]['cn_iso_3'];

// format address accordingly
$addressString = $this->staticInfoObj->formatAddress(',', $street, $city, $zip, $state, $country); // $country: alpha-3 ISO-code (e. g. DEU)
if(TYPO3_DLOG) {
t3lib_div::devLog('Google V3: AddressString: '.$addressString, 'wec_map_geocode', -1, array( street => $street, city => $city, zip => $zip, state => $state, country => $country) );
}
if ( !$addressString )
return array();
}
else
{
$addressString = $street.' '.$city.', '.$state.' '.$zip.', '.$country; // default: US-format
// $addressString = $street.','.$zip.' '.$city.','.$country; // Alternative German format for better search results
}

// build URL
$lookupstr = trim( $addressString );
# Google requires utf-8; convert query if neccessary
if ( $GLOBALS['TSFE']->renderCharset != 'utf-8' )
$lookupstr = utf8_encode( $lookupstr );