function getlocations_cb_w3w_get in Get Locations 7
Same name and namespace in other branches
- 7.2 getlocations.module \getlocations_cb_w3w_get()
2 calls to getlocations_cb_w3w_get()
- getlocations_cb_w3w in ./
getlocations.module - getlocations_fields_save_locations in modules/
getlocations_fields/ getlocations_fields.module
File
- ./
getlocations.module, line 2125 - getlocations.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL
Code
function getlocations_cb_w3w_get($data, $type) {
$types = array(
'w3w',
'position',
);
if (in_array($type, $types)) {
$what3words_lic = variable_get('getlocations_what3words_lic', array(
'key' => '',
'url' => 'http://api.what3words.com',
));
$key = $what3words_lic['key'];
if ($key) {
$url = $what3words_lic['url'] . '/' . $type;
$opts = array(
'method' => 'POST',
'headers' => array(
'Content-Type' => 'application/x-www-form-urlencoded',
),
);
$datastr = 'key=' . $key;
if ($type == 'position') {
$datastr .= '&position=' . $data;
}
else {
$datastr .= '&string=' . $data;
}
$opts['data'] = $datastr;
$response = drupal_http_request($url, $opts);
if ($response->code == '200') {
return $response->data;
}
}
}
return FALSE;
}