geocoder.services.inc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Implements hook_services_resources().
  4. */
  5. function geocoder_services_resources() {
  6. return array(
  7. 'geocoder' => array(
  8. 'retrieve' => array(
  9. 'help' => 'Geocode data',
  10. 'file' => array('type' => 'inc', 'module' => 'geocoder', 'name' => 'geocoder.services'),
  11. 'callback' => 'geocoder_services_geocode',
  12. 'access callback' => 'geocoder_services_access',
  13. 'access arguments append' => TRUE,
  14. 'args' => array(
  15. array(
  16. 'name' => 'handler',
  17. 'type' => 'string',
  18. 'description' => 'The geocoder handler to use - google, gpx, kml etc.',
  19. 'source' => array('path' => '0'),
  20. 'optional' => FALSE,
  21. ),
  22. array(
  23. 'name' => 'data',
  24. 'type' => 'string',
  25. 'description' => 'Value to geocode',
  26. 'source' => array('param' => 'data'),
  27. 'optional' => FALSE,
  28. ),
  29. array(
  30. 'name' => 'output',
  31. 'type' => 'string',
  32. 'description' => 'Output Format (GPX, WKT, etc.)',
  33. 'source' => array('param' => 'output'),
  34. 'optional' => TRUE,
  35. ),
  36. ),
  37. ),
  38. 'index' => array(
  39. 'help' => 'List Geocoder Capabilities',
  40. 'file' => array('type' => 'inc', 'module' => 'geocoder', 'name' => 'geocoder.services'),
  41. 'callback' => 'geocoder_services_capabilities',
  42. 'access callback' => TRUE,
  43. ),
  44. ),
  45. );
  46. }
  47. function geocoder_services_access($handler, $data, $output) {
  48. if ($handler == 'default') {
  49. $handler == 'json';
  50. }
  51. return geocoder_service_check_perms($handler);
  52. }
  53. /**
  54. * Callback for geocoding service
  55. *
  56. * @param string $handler
  57. * @param string $data
  58. * @return object
  59. */
  60. function geocoder_services_geocode($handler, $data, $format = 'default') {
  61. geophp_load();
  62. geocoder_service_check_request($handler, $format);
  63. $geom = geocoder($handler, $data);
  64. if (!$format || $format == 'default') {
  65. $result = $geom->out('json');
  66. return json_decode($result);
  67. }
  68. else {
  69. return $geom->out($format);
  70. }
  71. }
  72. function geocoder_services_capabilities() {
  73. geophp_load();
  74. $handlers = array();
  75. foreach (geocoder_handler_info() as $hid => $handler) {
  76. $handlers[$hid] = $handler['title'] . ' - ' . $handler['description'];
  77. }
  78. $object = new stdClass();
  79. $object->handlers = $handlers;
  80. $object->output = geoPHP::getAdapterMap();
  81. return $object;
  82. }