'Multimap', 'url' => 'http://www.multimap.co.uk', 'tos' => 'http://www.multimap.com/about/legal_and_copyright/', 'general' => TRUE, ); } /** * Perform a geocode on a location array * @param $location * The location array to process. * @return * an associative array with keys 'lat' and 'lon' containing the coordinates. */ function multimap_geocode_location($location = array()) { $key = variable_get('location_geocode_multimap_key', ''); if (empty($key)) { watchdog('Location', 'Multimap does not appear to have a key, please configure a key', NULL, WATCHDOG_WARNING); return NULL; } $query = array( 'countryCode' => _multimap_iso_country_map($location['country']), 'postalCode' => $location['postal_code'], 'city' => $location['city'], 'street' => $location['street'], ); $url = url('http://developer.multimap.com/API/geocode/1.2/'. drupal_urlencode($key), array( 'query' => $query, 'external' => TRUE, )); $http_reply = drupal_http_request($url); $error_match = array(); preg_match('/errorCode="(.*?)"/', $http_reply->data, $error_match); if (isset($error_match[1])) { watchdog('Location', 'Multimap geocode error: %error', array('%error' => $error_match[1]), WATCHDOG_ERROR); return NULL; } $latlon_match = array(); preg_match_all('/<(Lat|Lon)>(.*?)<\/\1>/', $http_reply->data, $latlon_match, PREG_SET_ORDER); if (count($latlon_match) == 2) { // [0/1][1] contains the Lat or Lon key matched in the XML, [0/1][2] contains the corresponding value $result = array(); $result[drupal_strtolower($latlon_match[0][1])] = $latlon_match[0][2]; $result[drupal_strtolower($latlon_match[1][1])] = $latlon_match[1][2]; return $result; } else { watchdog('Location', 'Multimap geocode error finding Lat/Lon in the response', NULL, WATCHDOG_ERROR); return NULL; } // Shouldn't really ever get here.... return NULL; } /** * General settings for this geocoder. */ function multimap_geocode_settings() { $form = array(); $form['location_geocode_multimap_key'] = array( '#type' => 'textfield', '#title' => t('Multimap API Key'), '#size' => 19, '#maxlength' => 19, '#default_value' => variable_get('location_geocode_multimap_key', ''), '#description' => t( 'In order to use the Multimap API geocoding server, you will need an API key. You can obtain one at the !sign_up_link for the !multimaps_api.', array( '!sign_up_link' => l(t('sign up page'), 'https://www.multimap.com/my/register/?openapi_create=1', array('absolute' => TRUE)), '!multimaps_api' => l(t('Multimaps API'), 'http://www.multimap.com/openapi/', array('absolute' => TRUE)), ) ), ); return $form; } function _multimap_iso_country_map($code) { $codes = array('uk' => 'GB'); return isset($codes[$code]) ? $codes[$code] : drupal_strtoupper($code); }