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