gpx.inc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php // $Id: gpx.inc,v 1.1 2009/03/02 18:14:07 vauxia Exp $
  2. /**
  3. * @file
  4. *
  5. * Parsing utilities for GPX track files. Originally written to cover a more
  6. * comprehensive usage than what Geocode is doing, but handy nonetheless.
  7. *
  8. */
  9. /**
  10. * Plugins are described by creating a $plugin array which will be used
  11. * by the system that includes this file.
  12. */
  13. $plugin = array(
  14. 'title' => t("GPX"),
  15. 'description' => t('Get the geomtry of a GPX string or file'),
  16. 'callback' => 'geocoder_gpx',
  17. 'field_types' => array('text', 'text_long', 'file', 'computed'),
  18. 'field_callback' => 'geocoder_gpx_field',
  19. );
  20. /**
  21. * Process GPX
  22. */
  23. function geocoder_gpx($gpx_string, $options = array()) {
  24. geophp_load();
  25. return geoPHP::load($gpx_string, 'gpx');
  26. }
  27. function geocoder_gpx_field($field, $field_item) {
  28. if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
  29. return geocoder_gpx($field_item['value']);
  30. }
  31. if ($field['type'] == 'file') {
  32. if ($field_item['fid']) {
  33. $file = file_load($field_item['fid']);
  34. $gpx = file_get_contents($file->uri);
  35. return geocoder_gpx($gpx);
  36. }
  37. }
  38. }