first import
This commit is contained in:
50
sites/all/modules/geocoder/plugins/geocoder_handler/exif.inc
Normal file
50
sites/all/modules/geocoder/plugins/geocoder_handler/exif.inc
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
$plugin = array(
|
||||
'title' => t("Image/exif"),
|
||||
'description' => t('Get a location from an image that was taken with a GPS enabled phone or camera'),
|
||||
'callback' => 'geocoder_exif',
|
||||
'field_types' => array('file', 'image'),
|
||||
'field_callback' => 'geocoder_exif_field',
|
||||
);
|
||||
|
||||
function geocoder_exif($url, $options = array()) {
|
||||
// Invoke hook_file_download to check permissions
|
||||
// We are essentially duplicating the logic found in file.inc file_download()
|
||||
foreach (module_implements('file_download') as $module) {
|
||||
$function = $module . '_file_download';
|
||||
$result = $function($url);
|
||||
if ($result == -1) {
|
||||
drupal_set_message(t('You do not have permission to access this file'), 'error');
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// The user has permission to access the file. Geocode it.
|
||||
geophp_load();
|
||||
if ($data = exif_read_data($url)) {
|
||||
if (!isset($data['GPSLatitudeRef'])) return FALSE;
|
||||
$lat = geocoder_exif_from($data['GPSLatitudeRef'], $data['GPSLatitude']);
|
||||
$lon = geocoder_exif_from($data['GPSLongitudeRef'], $data['GPSLongitude']);
|
||||
$point = new Point($lon, $lat);
|
||||
return $point;
|
||||
}
|
||||
else return FALSE;
|
||||
}
|
||||
|
||||
function geocoder_exif_field($field, $field_item) {
|
||||
if ($field_item['fid']) {
|
||||
$file = file_load($field_item['fid']);
|
||||
return geocoder_exif($file->uri);
|
||||
}
|
||||
}
|
||||
|
||||
function geocoder_exif_from($dir, $data) {
|
||||
foreach ($data as $k => $item) {
|
||||
list($deg, $pct) = explode('/', $item);
|
||||
if ($pct) $data[$k] = $deg / $pct;
|
||||
}
|
||||
$point = (float) $data[0] + ($data[1] / 60) + ($data[2] / 3600);
|
||||
if (in_array($dir, array('S', 'W'))) $point = $point * -1;
|
||||
return $point;
|
||||
}
|
177
sites/all/modules/geocoder/plugins/geocoder_handler/google.inc
Normal file
177
sites/all/modules/geocoder/plugins/geocoder_handler/google.inc
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a google geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Google Geocoder"),
|
||||
'description' => t('Geocodes via google geocoder'),
|
||||
'callback' => 'geocoder_google',
|
||||
'field_types' => array('text', 'text_long', 'addressfield', 'location', 'text_with_summary', 'computed', 'taxonomy_term_reference'),
|
||||
'field_callback' => 'geocoder_google_field',
|
||||
'settings_callback' => 'geocoder_google_form',
|
||||
'terms_of_service' => 'http://code.google.com/apis/maps/documentation/geocoding/#Limits',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_google($address, $options = array()) {
|
||||
try {
|
||||
geophp_load();
|
||||
|
||||
$query = array(
|
||||
'address' => $address,
|
||||
'sensor' => 'false',
|
||||
);
|
||||
|
||||
$url = url("http://maps.googleapis.com/maps/api/geocode/json", array('query' => $query));
|
||||
$result = drupal_http_request($url);
|
||||
|
||||
if (isset($result->error)) {
|
||||
$args = array(
|
||||
'@code' => $result->code,
|
||||
'@error' => $result->error,
|
||||
);
|
||||
$msg = t('HTTP request to google API failed.\nCode: @code\nError: @error', $args);
|
||||
throw new Exception($msg);
|
||||
}
|
||||
|
||||
$data = json_decode($result->data);
|
||||
|
||||
if ($data->status != 'OK') {
|
||||
$args = array('@status' => $data->status);
|
||||
$msg = t('Google API returned bad status.\nStatus: @status', $args);
|
||||
throw new Exception($msg);
|
||||
}
|
||||
|
||||
$geometries = array();
|
||||
|
||||
foreach ($data->results as $item) {
|
||||
// Check if we should reject these results
|
||||
if (isset($options['reject_results'])) {
|
||||
if (in_array($item->geometry->location_type, $options['reject_results'], TRUE)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Construct a geoPHP Geometry depending on what type of geometry we want returned (defaults to point)
|
||||
if (!isset($options['geometry_type']) || $options['geometry_type'] == 'point') {
|
||||
$geom = new Point($item->geometry->location->lng, $item->geometry->location->lat);
|
||||
}
|
||||
elseif ($options['geometry_type'] == 'bounds') {
|
||||
$points = array(
|
||||
new Point($item->geometry->bounds->southwest->lng, $item->geometry->bounds->southwest->lat),
|
||||
new Point($item->geometry->bounds->southwest->lng, $item->geometry->bounds->northeast->lat),
|
||||
new Point($item->geometry->bounds->northeast->lng, $item->geometry->bounds->northeast->lat),
|
||||
new Point($item->geometry->bounds->northeast->lng, $item->geometry->bounds->southwest->lat),
|
||||
new Point($item->geometry->bounds->southwest->lng, $item->geometry->bounds->southwest->lat),
|
||||
);
|
||||
$geom = new Polygon(array(new LineString($points)));
|
||||
}
|
||||
elseif ($options['geometry_type'] == 'viewport') {
|
||||
$points = array(
|
||||
new Point($item->geometry->viewport->southwest->lng, $item->geometry->viewport->southwest->lat),
|
||||
new Point($item->geometry->viewport->southwest->lng, $item->geometry->viewport->northeast->lat),
|
||||
new Point($item->geometry->viewport->northeast->lng, $item->geometry->viewport->northeast->lat),
|
||||
new Point($item->geometry->viewport->northeast->lng, $item->geometry->viewport->southwest->lat),
|
||||
new Point($item->geometry->viewport->southwest->lng, $item->geometry->viewport->southwest->lat),
|
||||
);
|
||||
$geom = new Polygon(array(new LineString($points)));
|
||||
}
|
||||
|
||||
// Add additional metadata to the geometry - it might be useful!
|
||||
$geom->data = array();
|
||||
$geom->data['geocoder_accuracy'] = $item->geometry->location_type;
|
||||
$geom->data['geocoder_formatted_address'] = $item->formatted_address;
|
||||
$geom->data['geocoder_address_components'] = $item->address_components;
|
||||
|
||||
$geometries[] = $geom;
|
||||
}
|
||||
|
||||
if (empty($geometries)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we should return all results as a compound geometry
|
||||
if (isset($options['all_results'])) {
|
||||
if ($options['all_results']) {
|
||||
return geoPHP::geometryReduce($geometries);
|
||||
}
|
||||
}
|
||||
// The connonical geometry is the first result (best guesse)
|
||||
$geometry = array_shift($geometries);
|
||||
|
||||
// If there are any other geometries, these are auxiliary geometries that represent "alternatives"
|
||||
if (count($geometries)) {
|
||||
$geometry->data['geocoder_alternatives'] = $geometries;
|
||||
}
|
||||
|
||||
return $geometry;
|
||||
} catch (Exception $e) {
|
||||
watchdog_exception('geocoder', $e);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
function geocoder_google_field($field, $field_item, $options = array()) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'text_with_summary' || $field['type'] == 'computed') {
|
||||
return geocoder_google($field_item['value'], $options);
|
||||
}
|
||||
if ($field['type'] == 'addressfield') {
|
||||
$address = geocoder_widget_parse_addressfield($field_item);
|
||||
return geocoder_google($address, $options);
|
||||
}
|
||||
if ($field['type'] == 'location') {
|
||||
$address = geocoder_widget_parse_locationfield($field_item);
|
||||
return geocoder_google($address, $options);
|
||||
}
|
||||
if ($field['type'] == 'taxonomy_term_reference') {
|
||||
$term = taxonomy_term_load($field_item['tid']);
|
||||
return geocoder_google($term->name);
|
||||
}
|
||||
}
|
||||
|
||||
function geocoder_google_form($default_values = array()) {
|
||||
$form = array();
|
||||
|
||||
$form['geometry_type'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => 'Geometry Type',
|
||||
'#options' => array(
|
||||
'point' => 'Point (default)',
|
||||
'bounds' => 'Bounding Box',
|
||||
'viewport' => 'Viewport',
|
||||
),
|
||||
'#default_value' => isset($default_values['geometry_type']) ? $default_values['geometry_type'] : 'point',
|
||||
);
|
||||
|
||||
$form['all_results'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => 'Geocode all alternative results',
|
||||
'#default_value' => isset($default_values['all_results']) ? $default_values['all_results'] : FALSE,
|
||||
'#description' => 'Often an ambiguous address (such as "Springfield USA") can result in multiple hits. By default we only return the first (best guess) result. Check this to return all results as a Multi-Geometry (MultiPoint or MultiPolygon).',
|
||||
);
|
||||
|
||||
$form['reject_results'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => 'Reject Results',
|
||||
'#options' => array(
|
||||
'APPROXIMATE' => 'APPROXIMATE: indicates that the returned result is approximate.',
|
||||
'GEOMETRIC_CENTER' => 'GEOMETRIC_CENTER: indicates that the returned result is the geometric center of a result such as a polyline (for example, a street) or polygon (region).',
|
||||
'RANGE_INTERPOLATED' => 'RANGE_INTERPOLATED: indicates that the returned result reflects an approximation (usually on a road) interpolated between two precise points (such as intersections). Interpolated results are generally returned when rooftop geocodes are unavailable for a street address.',
|
||||
'ROOFTOP' => 'ROOFTOP: indicates that the returned result is a precise geocode for which we have location information accurate down to street address precision.',
|
||||
),
|
||||
'#default_value' => isset($default_values['reject_results']) ? $default_values['reject_results'] : array(),
|
||||
'#description' => 'Reject results that do not meet a certain level of quality or precision. Check all types of results to reject.',
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
44
sites/all/modules/geocoder/plugins/geocoder_handler/gpx.inc
Normal file
44
sites/all/modules/geocoder/plugins/geocoder_handler/gpx.inc
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php // $Id: gpx.inc,v 1.1 2009/03/02 18:14:07 vauxia Exp $
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Parsing utilities for GPX track files. Originally written to cover a more
|
||||
* comprehensive usage than what Geocode is doing, but handy nonetheless.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("GPX"),
|
||||
'description' => t('Get the geomtry of a GPX string or file'),
|
||||
'callback' => 'geocoder_gpx',
|
||||
'field_types' => array('text', 'text_long', 'file', 'computed'),
|
||||
'field_callback' => 'geocoder_gpx_field',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process GPX
|
||||
*/
|
||||
function geocoder_gpx($gpx_string, $options = array()) {
|
||||
geophp_load();
|
||||
return geoPHP::load($gpx_string, 'gpx');
|
||||
}
|
||||
|
||||
function geocoder_gpx_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
|
||||
return geocoder_gpx($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'file') {
|
||||
if ($field_item['fid']) {
|
||||
$file = file_load($field_item['fid']);
|
||||
$gpx = file_get_contents($file->uri);
|
||||
return geocoder_gpx($gpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
sites/all/modules/geocoder/plugins/geocoder_handler/json.inc
Normal file
40
sites/all/modules/geocoder/plugins/geocoder_handler/json.inc
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a google geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("GeoJSON"),
|
||||
'description' => t('Get the geometry of a GeoJSON string, file, or URL'),
|
||||
'callback' => 'geocoder_json',
|
||||
'field_types' => array('text', 'text_long', 'file', 'computed'),
|
||||
'field_callback' => 'geocoder_json_field',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_json($json_string, $options = array()) {
|
||||
geophp_load();
|
||||
return geoPHP::load($json_string, 'json');
|
||||
}
|
||||
|
||||
function geocoder_json_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
|
||||
return geocoder_json($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'file') {
|
||||
if ($field_item['fid']) {
|
||||
$file = file_load($field_item['fid']);
|
||||
$json = file_get_contents($file->uri);
|
||||
return geocoder_json($json);
|
||||
}
|
||||
}
|
||||
}
|
40
sites/all/modules/geocoder/plugins/geocoder_handler/kml.inc
Normal file
40
sites/all/modules/geocoder/plugins/geocoder_handler/kml.inc
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a kml geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("KML"),
|
||||
'description' => t('Get the geometry out of a KML string, file, or URL'),
|
||||
'callback' => 'geocoder_kml',
|
||||
'field_types' => array('text', 'text_long', 'file', 'computed'),
|
||||
'field_callback' => 'geocoder_kml_field',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_kml($kml_string, $options = array()) {
|
||||
geophp_load();
|
||||
return geoPHP::load($kml_string, 'kml');
|
||||
}
|
||||
|
||||
function geocoder_kml_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
|
||||
return geocoder_kml($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'file') {
|
||||
if ($field_item['fid']) {
|
||||
$file = file_load($field_item['fid']);
|
||||
$kml = file_get_contents($file->uri);
|
||||
return geocoder_kml($kml);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a google geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Latitude / Longitude"),
|
||||
'description' => t('Parse location from freeform latitude and longitude string'),
|
||||
'callback' => 'geocoder_latlon',
|
||||
'field_types' => array('text', 'text_long', 'text_with_summary', 'computed'),
|
||||
'field_callback' => 'geocoder_latlon_field',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_latlon($latlon_string, $options = array()) {
|
||||
geophp_load();
|
||||
|
||||
$delims = array("," , "/" , " " , "\t");
|
||||
|
||||
foreach ($delims as $delim) {
|
||||
$parts = explode($delim, $latlon_string);
|
||||
if (count($parts) == 2) {
|
||||
$lat = geocoder_latlon_DMStoDEC(trim($parts[0]));
|
||||
$lon = geocoder_latlon_DMStoDEC(trim($parts[1]));
|
||||
return new Point($lon, $lat);
|
||||
}
|
||||
}
|
||||
|
||||
// Failed to parse
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function geocoder_latlon_DMStoDEC($dms) {
|
||||
if (is_numeric($dms)) {
|
||||
// It's already decimal degrees, just return it
|
||||
return $dms;
|
||||
}
|
||||
|
||||
// If it contains both an H and M, then it's an angular hours
|
||||
if (stripos($dms, 'H') !== FALSE && stripos($dms, 'M') !== FALSE) {
|
||||
$dms = strtr($dms, "'\"HOURSMINTECNDAhoursmintecnda", " ");
|
||||
$dms = preg_replace('/\s\s+/', ' ', $dms);
|
||||
|
||||
$dms = explode(" ", $dms);
|
||||
$deg = $dms[0];
|
||||
$min = $dms[1];
|
||||
$sec = $dms[2];
|
||||
|
||||
$dec = floatval(($deg*15) + ($min/4) + ($sec/240));
|
||||
|
||||
return $dec;
|
||||
}
|
||||
|
||||
// If it contains an S or a W, then it's a negative
|
||||
if (stripos($dms, 'S') !== FALSE || stripos($dms, 'W') !== FALSE) {
|
||||
$direction = -1;
|
||||
}
|
||||
else {
|
||||
$direction = 1;
|
||||
}
|
||||
|
||||
// Strip all characters and replace them with empty space
|
||||
$dms = strtr($dms, "<EFBFBD>'\"NORTHSEAWnorthseaw'", " ");
|
||||
$dms = preg_replace('/\s\s+/', ' ', $dms);
|
||||
|
||||
$dms = explode(" ", $dms);
|
||||
$deg = $dms[0];
|
||||
$min = $dms[1];
|
||||
$sec = $dms[2];
|
||||
|
||||
// Direction should be checked only for nonnegative coordinates
|
||||
$dec = floatval($deg+((($min*60)+($sec))/3600));
|
||||
if ($dec > 0) {
|
||||
$dec = $direction * $dec;
|
||||
}
|
||||
return $dec;
|
||||
}
|
||||
|
||||
|
||||
function geocoder_latlon_field($field, $field_item) {
|
||||
return geocoder_latlon($field_item['value']);
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a MapQuest Nominatim geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("MapQuest Nominatim"),
|
||||
'description' => t('Geocodes via MapQuest Nominatim'),
|
||||
'callback' => 'geocoder_mapquest_nominatim',
|
||||
'field_types' => array('text', 'text_long', 'addressfield', 'location', 'text_with_summary', 'computed', 'taxonomy_term_reference'),
|
||||
'field_callback' => 'geocoder_mapquest_nominatim_field',
|
||||
'terms_of_service' => 'http://developer.mapquest.com/web/info/terms-of-use',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_mapquest_nominatim($address, $options = array()) {
|
||||
$geocoder_settings = variable_get("geocoder_settings", array());
|
||||
$api_url = "http://open.mapquestapi.com/nominatim/v1/search";
|
||||
$params = array(
|
||||
'q' => str_replace(' ', '+', $address),
|
||||
'format' => 'json',
|
||||
'addressdetails' => 0,
|
||||
'limit' => 1,
|
||||
'osm_type' => 'N',
|
||||
);
|
||||
$request = drupal_http_request($api_url . '?' . drupal_http_build_query($params));
|
||||
$data = json_decode($request->data);
|
||||
return _geocoder_mapquest_nominatim_geometry($data);
|
||||
}
|
||||
|
||||
function geocoder_mapquest_nominatim_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'text_with_summary' || $field['type'] == 'computed') {
|
||||
return geocoder_mapquest_nominatim($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'addressfield') {
|
||||
$address = geocoder_widget_parse_addressfield($field_item);
|
||||
return geocoder_mapquest_nominatim($address);
|
||||
}
|
||||
if ($field['type'] == 'location') {
|
||||
$address = geocoder_widget_parse_locationfield($field_item);
|
||||
return geocoder_mapquest_nomination($address);
|
||||
}
|
||||
if ($field['type'] == 'taxonomy_term_reference') {
|
||||
$term = taxonomy_term_load($field_item['tid']);
|
||||
return geocoder_mapquest_nominatim($term->name);
|
||||
}
|
||||
}
|
||||
|
||||
function _geocoder_mapquest_nominatim_geometry(&$data) {
|
||||
if (!isset($data[0]->lon)) {
|
||||
return NULL;
|
||||
}
|
||||
geophp_load();
|
||||
return new Point($data[0]->lon, $data[0]->lat);
|
||||
}
|
43
sites/all/modules/geocoder/plugins/geocoder_handler/wkt.inc
Normal file
43
sites/all/modules/geocoder/plugins/geocoder_handler/wkt.inc
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a WKT geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("WKT"),
|
||||
'description' => t('Get the geometry of a WKT string'),
|
||||
'callback' => 'geocoder_wkt',
|
||||
'field_types' => array('text', 'text_long', 'file', 'geofield', 'computed'),
|
||||
'field_callback' => 'geocoder_wkt_field',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process WKT
|
||||
*/
|
||||
function geocoder_wkt($wkt, $options = array()) {
|
||||
geophp_load();
|
||||
return geoPHP::load($wkt, 'wkt');
|
||||
}
|
||||
|
||||
function geocoder_wkt_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
|
||||
return geocoder_wkt($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'geofield') {
|
||||
return geocoder_wkt($field_item['wkt']);
|
||||
}
|
||||
if ($field['type'] == 'file') {
|
||||
if ($field_item['fid']) {
|
||||
$file = file_load($field_item['fid']);
|
||||
$wkt = file_get_contents($file->uri);
|
||||
return geocoder_wkt($wkt);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a yahoo geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Yahoo Placefinder"),
|
||||
'description' => t('Geocodes via Yahoo Placefinder'),
|
||||
'callback' => 'geocoder_yahoo',
|
||||
'field_types' => array('text', 'text_long', 'addressfield', 'location', 'text_with_summary', 'computed', 'taxonomy_term_reference'),
|
||||
'field_callback' => 'geocoder_yahoo_field',
|
||||
'terms_of_service' => 'http://developer.yahoo.com/geo/placefinder/',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_yahoo($address, $options = array()) {
|
||||
global $base_path;
|
||||
$geocoder_settings = variable_get("geocoder_settings", array());
|
||||
|
||||
if (!empty($geocoder_settings["geocoder_apikey_yahoo"])) {
|
||||
$consumer_key = $geocoder_settings["geocoder_apikey_yahoo"];
|
||||
}
|
||||
else {
|
||||
drupal_set_message("You must set up your Yahoo API key. Click <a href='$base_path/admin/config/content/geocoder'>here</a>",'error');
|
||||
return;
|
||||
}
|
||||
|
||||
$request = drupal_http_request("http://where.yahooapis.com/geocode?location=" . urlencode($address) . "&flags=J&appid={$consumer_key}");
|
||||
$data = json_decode($request->data);
|
||||
|
||||
geophp_load();
|
||||
return _geocoder_yahoo_geometry($data);
|
||||
}
|
||||
|
||||
function geocoder_yahoo_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'text_with_summary' || $field['type'] == 'computed') {
|
||||
return geocoder_yahoo($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'addressfield') {
|
||||
$address = geocoder_widget_parse_addressfield($field_item);
|
||||
return geocoder_yahoo($address);
|
||||
}
|
||||
if ($field['type'] == 'location') {
|
||||
$address = geocoder_widget_parse_locationfield($field_item);
|
||||
return geocoder_yahoo($address);
|
||||
}
|
||||
if ($field['type'] == 'taxonomy_term_reference') {
|
||||
$term = taxonomy_term_load($field_item['tid']);
|
||||
return geocoder_yahoo($term->name);
|
||||
}
|
||||
}
|
||||
|
||||
function _geocoder_yahoo_geometry(&$data) {
|
||||
if (!isset($data->ResultSet)) {
|
||||
return NULL;
|
||||
}
|
||||
// Yahoo Placefinder API v2.
|
||||
elseif (isset($data->ResultSet->Result->longitude)) {
|
||||
return new Point($data->ResultSet->Result->longitude, $data->ResultSet->Result->latitude);
|
||||
}
|
||||
// Yahoo Placefinder API v1.
|
||||
elseif (isset($data->ResultSet->Results[0]->longitude)) {
|
||||
return new Point($data->ResultSet->Results[0]->longitude, $data->ResultSet->Results[0]->latitude);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a yandex geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Yandex (Яндекс.Карт)"),
|
||||
'description' => t('Geocodes addresses via Yandex (Яндекс.Карт)'),
|
||||
'callback' => 'geocoder_yandex',
|
||||
'field_types' => array('text','text_long','addressfield', 'location','text_with_summary','computed', 'taxonomy_term_reference'),
|
||||
'field_callback' => 'geocoder_yandex_field',
|
||||
'terms_of_service' => 'http://api.yandex.ru/maps/geocoder/doc/desc/concepts/About.xml',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Address
|
||||
*/
|
||||
function geocoder_yandex($address, $options = array()) {
|
||||
global $base_path;
|
||||
$geocoder_settings = variable_get("geocoder_settings", array());
|
||||
|
||||
if (!empty($geocoder_settings["geocoder_apikey_yandex"])) {
|
||||
$consumer_key = $geocoder_settings["geocoder_apikey_yandex"];
|
||||
}
|
||||
else {
|
||||
drupal_set_message("You must set up your Yandex API key. Click <a href='$base_path/admin/config/content/geocoder'>here</a>",'error');
|
||||
return;
|
||||
}
|
||||
|
||||
$params = array (
|
||||
'format' => 'json',
|
||||
'results' => 1,
|
||||
'key' => $consumer_key,
|
||||
'geocode' => $address,
|
||||
);
|
||||
$request = drupal_http_request("http://geocode-maps.yandex.ru/1.x/?" . http_build_query($params));
|
||||
$data = json_decode($request->data);
|
||||
|
||||
return _geocoder_yandex_geometry($data);
|
||||
}
|
||||
|
||||
function geocoder_yandex_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'text_with_summary' || $field['type'] == 'computed') {
|
||||
return geocoder_yandex($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'addressfield') {
|
||||
$address = geocoder_widget_parse_addressfield($field_item);
|
||||
return geocoder_yandex($address);
|
||||
}
|
||||
if ($field['type'] == 'location') {
|
||||
$address = geocoder_widget_parse_locationfield($field_item);
|
||||
return geocoder_google($address);
|
||||
}
|
||||
if ($field['type'] == 'taxonomy_term_reference') {
|
||||
$term = taxonomy_term_load($field_item['tid']);
|
||||
return geocoder_yandex($term->name);
|
||||
}
|
||||
}
|
||||
|
||||
function _geocoder_yandex_geometry(&$data) {
|
||||
try {
|
||||
geophp_load();
|
||||
|
||||
if (isset($data->error)) {
|
||||
$args = array(
|
||||
'@status' => $data->error->status,
|
||||
'@error' => $data->error->message,
|
||||
);
|
||||
$msg = t('Yandex API has reported an error.\nStatus: @status\nError: @error', $args);
|
||||
throw new Exception($msg);
|
||||
}
|
||||
|
||||
if($data->response->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$loc = explode(' ', $data->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos);
|
||||
return new Point ($loc[0], $loc[1]);
|
||||
} catch (Exception $e) {
|
||||
watchdog_exception('geocoder', $e);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user