Loading README.txt +11 −8 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ $Id$ DESCRIPTION ===================== The module makes it possible for other module developers easily to use Yahoo Geocoding API to find geo coordinates for a given address. Yahoo! PlaceFinder geocoding API to find geo coordinates for a given address. The module it self don't do anything out of the box, by provides a function to find the geo coordinates. Loading @@ -17,15 +17,18 @@ DEVELOPERS ===================== Call the function yahoo_geocoding_api_geocode($address) with your address as argument. It uses the API's location argument, see http://developer.yahoo.com/maps/rest/V1/geocode.html. https://developer.yahoo.com/geo/placefinder/. The function will return an array with latitude, longitude and accuracy. REQUIREMENTS REQUIREMENTS - 6.x-2.0 ===================== - The keys_api module (version 6.x-1.x only), www.drupal.org/project/keys - PHP should be configured with allow_url_fopen. - A Yahoo Application ID. Sign up at http://developer.yahoo.com/maps/rest/V1/geocode.html. - The keys module (version 6.x-2.x only), www.drupal.org/project/keys - A Yahoo Application ID. Sign up at https://developer.apps.yahoo.com/dashboard/createKey.html. DRUPAL 7 ===================== In development. Waiting on Drupal 7 version of the keys module. DRUPAL 5 ===================== Loading @@ -33,7 +36,7 @@ No support planned. CONTRIBUTORS ===================== Jens Beltofte Sørensen (beltofte@gmail.com) Jens Beltofte Sørensen - http://drupal.org/user/151799 SPONSORS ===================== Loading yahoo_geocoding_api.info +2 −3 Original line number Diff line number Diff line ; $Id$ name = Yahoo Geocoding API description = Adding support for Yahoo Geocoding API, so we can fallback on this if Google's service can't find the address. version = VERSION description = "Adding support for Yahoo Geocoding API. Use the module to find geo coordinates for addresses." core = 6.x dependencies[] = keys_api No newline at end of file dependencies[] = keys No newline at end of file yahoo_geocoding_api.installdeleted 100644 → 0 +0 −61 Original line number Diff line number Diff line <?php // $Id$ /** * @file yahoo_geocoding_api.install * Install file for the yahoo_geocoding_api module. */ /** * Implementation of hook_install(). */ function yahoo_geocoding_api_install() { // Create tables. drupal_install_schema('yahoo_geocoding_api'); } /** * Implementation of hook_uninstall(). */ function yahoo_geocoding_api_uninstall() { // Delete menu links. db_query("DELETE FROM {menu_links} WHERE module = 'yahoo_geocoding_api'"); menu_cache_clear_all(); // Delete variables db_query("DELETE FROM {variable} WHERE name LIKE 'yahoo_geocoding_api_%'"); // Remove tables. drupal_uninstall_schema('yahoo_geocoding_api'); } /** * Implementation of hook_schema(). */ function yahoo_geocoding_api_schema() { $schema = array(); return $schema; } /** * Implementation of hook_requirements(). */ function yahoo_geocoding_api_requirements($phase) { $requirements = array(); if ($phase == 'runtime') { $requirements['allow_url_fopen'] = array( 'title' => t('PHP allow URL fopen'), ); if (ini_get('allow_url_fopen')) { $requirements['allow_url_fopen']['value'] = t('Enabled'); $requirements['allow_url_fopen']['severity'] = REQUIREMENT_OK; } else { $requirements['allow_url_fopen']['value'] = t('Disabled'); $requirements['allow_url_fopen']['severity'] = REQUIREMENT_ERROR; $requirements['allow_url_fopen']['description'] = t('Allow URL fopen is required to use the Yahoo Geocoding API module. Please enable it in your php.ini file.'); } } return $requirements; } yahoo_geocoding_api.module +74 −18 Original line number Diff line number Diff line Loading @@ -16,34 +16,90 @@ function yahoo_geocoding_api_perm() { /** * Finding geo code using Yahoo Geocoding API * * @param string $address * @return array * @param mixed $address * - if $address is a string will the request be made using the location * parameter. See http://goo.gl/mKvnq. * - if $address is an array will the request be made using the seperate * location parameters. Notice the keys in the array should match one * or more of the location parameters available on http://goo.gl/osNtT. * @param array $control * An array containing one or more control parameters. The following * are supported: locale, start, count, offset, flags, gflags. * See http://goo.gl/BS6Dq. * @return bool $raw * Return the formattet result or the raw result from Yahoo. * If this is TRUE can the result format be controlled in the * flags parameter. * * @return mixed * If $raw is FALSE will the return value be an array. Else is the * format controlled by the flags parameter. */ function yahoo_geocoding_api_geocode($address) { function yahoo_geocoding_api_geocode($address, $control = array(), $raw = FALSE) { // Checking if the allow_url_fopen is enabled. if (ini_get('allow_url_fopen') == 0) { watchdog('Yahoo Geocoding API', 'Allow URL fopen is required to use the yahoo_geocoding_api_geocode() function.'); drupal_set_message(t('Yahoo Geocoding API: Allow URL fopen is required to use the yahoo_geocoding_api_geocode() function.'), 'error'); return NULL; } $key = yahoo_geocoding_api_get_key(); $data = NULL; $result = NULL; // If $address is a string is it added to the location paramter $params = array(); if (is_string($address)) { $params['location'] = urlencode($address); } else if (is_array($address)) { foreach ($address as $key => $value) { $params[$key] = urlencode($value); } } // Adding the control parameters if (!is_array($control) || !count($control)) { $params['flags'] = 'P'; } else { foreach ($control as $key => $value) { // $raw result is disabled so we remove the format flags. if (!$raw && $key == 'flags') { $value = array_flip(str_split($value)); unset($value['J'], $value['P']); $value['P'] = 'P'; $params[$key] = implode('', array_flip($value)); } else { $params[$key] = $value; } } } // Creating the URL $url = 'http://where.yahooapis.com/geocode?appid=' . yahoo_geocoding_api_get_key(); foreach ($params as $key => $value) { $url .= '&' . $key . '=' . $value; } // Executing the request try { // Using the file_get_contents instead of the drupal_http_request because it causes problems. $data = file_get_contents('http://local.yahooapis.com/MapsService/V1/geocode?appid=' . $key . '&output=php&location=' . urlencode($address)); $result = drupal_http_request($url); } catch (Exception $e) { } if (!empty($data)) { $data = unserialize($data); $result = $data['ResultSet']['Result']; if (in_array($result['precision'], array('address', 'street'))) { return array( 'accuracy' => $result['precision'], 'latitude' => $result['Latitude'], 'longitude' => $result['Longitude'], ); // Formatting the result or returning the raw result. if (!empty($result) && !empty($result->data)) { if ($raw) { return $result->data; } else { $data = unserialize($result->data); if (is_array($data['ResultSet']['Result'])) { return $data['ResultSet']['Result']; } } } return NULL; } Loading @@ -63,6 +119,6 @@ function yahoo_geocoding_api_keys_service() { * Retrieve the Yahoo applicaiton id */ function yahoo_geocoding_api_get_key() { $key = keys_api_get_key('Yahoo Geocoding API', $_SERVER['HTTP_HOST']); $key = keys_get_key('yahoo_geocoding_api'); return $key; } No newline at end of file Loading
README.txt +11 −8 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ $Id$ DESCRIPTION ===================== The module makes it possible for other module developers easily to use Yahoo Geocoding API to find geo coordinates for a given address. Yahoo! PlaceFinder geocoding API to find geo coordinates for a given address. The module it self don't do anything out of the box, by provides a function to find the geo coordinates. Loading @@ -17,15 +17,18 @@ DEVELOPERS ===================== Call the function yahoo_geocoding_api_geocode($address) with your address as argument. It uses the API's location argument, see http://developer.yahoo.com/maps/rest/V1/geocode.html. https://developer.yahoo.com/geo/placefinder/. The function will return an array with latitude, longitude and accuracy. REQUIREMENTS REQUIREMENTS - 6.x-2.0 ===================== - The keys_api module (version 6.x-1.x only), www.drupal.org/project/keys - PHP should be configured with allow_url_fopen. - A Yahoo Application ID. Sign up at http://developer.yahoo.com/maps/rest/V1/geocode.html. - The keys module (version 6.x-2.x only), www.drupal.org/project/keys - A Yahoo Application ID. Sign up at https://developer.apps.yahoo.com/dashboard/createKey.html. DRUPAL 7 ===================== In development. Waiting on Drupal 7 version of the keys module. DRUPAL 5 ===================== Loading @@ -33,7 +36,7 @@ No support planned. CONTRIBUTORS ===================== Jens Beltofte Sørensen (beltofte@gmail.com) Jens Beltofte Sørensen - http://drupal.org/user/151799 SPONSORS ===================== Loading
yahoo_geocoding_api.info +2 −3 Original line number Diff line number Diff line ; $Id$ name = Yahoo Geocoding API description = Adding support for Yahoo Geocoding API, so we can fallback on this if Google's service can't find the address. version = VERSION description = "Adding support for Yahoo Geocoding API. Use the module to find geo coordinates for addresses." core = 6.x dependencies[] = keys_api No newline at end of file dependencies[] = keys No newline at end of file
yahoo_geocoding_api.installdeleted 100644 → 0 +0 −61 Original line number Diff line number Diff line <?php // $Id$ /** * @file yahoo_geocoding_api.install * Install file for the yahoo_geocoding_api module. */ /** * Implementation of hook_install(). */ function yahoo_geocoding_api_install() { // Create tables. drupal_install_schema('yahoo_geocoding_api'); } /** * Implementation of hook_uninstall(). */ function yahoo_geocoding_api_uninstall() { // Delete menu links. db_query("DELETE FROM {menu_links} WHERE module = 'yahoo_geocoding_api'"); menu_cache_clear_all(); // Delete variables db_query("DELETE FROM {variable} WHERE name LIKE 'yahoo_geocoding_api_%'"); // Remove tables. drupal_uninstall_schema('yahoo_geocoding_api'); } /** * Implementation of hook_schema(). */ function yahoo_geocoding_api_schema() { $schema = array(); return $schema; } /** * Implementation of hook_requirements(). */ function yahoo_geocoding_api_requirements($phase) { $requirements = array(); if ($phase == 'runtime') { $requirements['allow_url_fopen'] = array( 'title' => t('PHP allow URL fopen'), ); if (ini_get('allow_url_fopen')) { $requirements['allow_url_fopen']['value'] = t('Enabled'); $requirements['allow_url_fopen']['severity'] = REQUIREMENT_OK; } else { $requirements['allow_url_fopen']['value'] = t('Disabled'); $requirements['allow_url_fopen']['severity'] = REQUIREMENT_ERROR; $requirements['allow_url_fopen']['description'] = t('Allow URL fopen is required to use the Yahoo Geocoding API module. Please enable it in your php.ini file.'); } } return $requirements; }
yahoo_geocoding_api.module +74 −18 Original line number Diff line number Diff line Loading @@ -16,34 +16,90 @@ function yahoo_geocoding_api_perm() { /** * Finding geo code using Yahoo Geocoding API * * @param string $address * @return array * @param mixed $address * - if $address is a string will the request be made using the location * parameter. See http://goo.gl/mKvnq. * - if $address is an array will the request be made using the seperate * location parameters. Notice the keys in the array should match one * or more of the location parameters available on http://goo.gl/osNtT. * @param array $control * An array containing one or more control parameters. The following * are supported: locale, start, count, offset, flags, gflags. * See http://goo.gl/BS6Dq. * @return bool $raw * Return the formattet result or the raw result from Yahoo. * If this is TRUE can the result format be controlled in the * flags parameter. * * @return mixed * If $raw is FALSE will the return value be an array. Else is the * format controlled by the flags parameter. */ function yahoo_geocoding_api_geocode($address) { function yahoo_geocoding_api_geocode($address, $control = array(), $raw = FALSE) { // Checking if the allow_url_fopen is enabled. if (ini_get('allow_url_fopen') == 0) { watchdog('Yahoo Geocoding API', 'Allow URL fopen is required to use the yahoo_geocoding_api_geocode() function.'); drupal_set_message(t('Yahoo Geocoding API: Allow URL fopen is required to use the yahoo_geocoding_api_geocode() function.'), 'error'); return NULL; } $key = yahoo_geocoding_api_get_key(); $data = NULL; $result = NULL; // If $address is a string is it added to the location paramter $params = array(); if (is_string($address)) { $params['location'] = urlencode($address); } else if (is_array($address)) { foreach ($address as $key => $value) { $params[$key] = urlencode($value); } } // Adding the control parameters if (!is_array($control) || !count($control)) { $params['flags'] = 'P'; } else { foreach ($control as $key => $value) { // $raw result is disabled so we remove the format flags. if (!$raw && $key == 'flags') { $value = array_flip(str_split($value)); unset($value['J'], $value['P']); $value['P'] = 'P'; $params[$key] = implode('', array_flip($value)); } else { $params[$key] = $value; } } } // Creating the URL $url = 'http://where.yahooapis.com/geocode?appid=' . yahoo_geocoding_api_get_key(); foreach ($params as $key => $value) { $url .= '&' . $key . '=' . $value; } // Executing the request try { // Using the file_get_contents instead of the drupal_http_request because it causes problems. $data = file_get_contents('http://local.yahooapis.com/MapsService/V1/geocode?appid=' . $key . '&output=php&location=' . urlencode($address)); $result = drupal_http_request($url); } catch (Exception $e) { } if (!empty($data)) { $data = unserialize($data); $result = $data['ResultSet']['Result']; if (in_array($result['precision'], array('address', 'street'))) { return array( 'accuracy' => $result['precision'], 'latitude' => $result['Latitude'], 'longitude' => $result['Longitude'], ); // Formatting the result or returning the raw result. if (!empty($result) && !empty($result->data)) { if ($raw) { return $result->data; } else { $data = unserialize($result->data); if (is_array($data['ResultSet']['Result'])) { return $data['ResultSet']['Result']; } } } return NULL; } Loading @@ -63,6 +119,6 @@ function yahoo_geocoding_api_keys_service() { * Retrieve the Yahoo applicaiton id */ function yahoo_geocoding_api_get_key() { $key = keys_api_get_key('Yahoo Geocoding API', $_SERVER['HTTP_HOST']); $key = keys_get_key('yahoo_geocoding_api'); return $key; } No newline at end of file