public function __construct() { parent::__construct(); get_instance()->config->load('site_config', TRUE); // $api = get_instance()->config->item('google_app', 'site_config'); // $this->api_key = $api['simple_api_key']; $this->api_key = Api_key::value('google', 'developer_key'); if (empty($this->api_key)) { throw new Exception('Setup google api key.'); } }
/** * Autocomplete for company address */ public function google_autocomplete() { $term = $this->input->get('term'); $term = trim($term); try { $developer_key = Api_key::value('google', 'developer_key'); $gls = $this->load->library('gls'); $gls->set(array('key' => $developer_key)); $rows = $gls->autocomplete($term); if (!$rows or !isset($rows['predictions'])) { throw new Exception(); } $rows = $rows['predictions']; $data = array(); foreach ($rows as $row) { $data[] = array('id' => $row['id'], 'label' => $row['description']); } } catch (Exception $e) { exit; } header('Content-Type: application/json'); echo json_encode($data); exit; }