You are here

json.inc in Geocoder 7

File

plugins/geocoder_handler/json.inc
View source
<?php

/**
 * @file
 * Plugin to provide a google geocoder.
 */
$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');
}

/**
 * Plugin callback.
 */
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);
    }
  }
}

Functions

Namesort descending Description
geocoder_json Process Markup.
geocoder_json_field Plugin callback.