/** * Example for a location_input plugin input callback. * * @param $input * The text entered by the user. * @param array $options * The options for this plugin, as entered into the form specified by the * "form callback". * * @return * A location if the input could be parsed, NULL otherwise. The location has * to be a string in the format "LAT,LON", where LAT and LON are the decimal * latitude and longitude, respectively, of the location. */ function example_search_api_location_input_callback($input, array $options) { $location = geocoder($options['handler'], $input); if ($location) { $location = $location->centroid(); return $location->y() . ',' . $location->x(); } }
/** * geocoder * 存取 geocoder table * @param mixed $op * @param mixed $data * @access public * @return void */ function geocoder($op, $data) { $db = get_conn(); switch ($op) { case 'get': $sql = sprintf("select * from \"geocoder\" where address='%s'", $data['address']); $res = $db->GetAll($sql); logsql($sql, $res); if (count($res) == 1) { return array(1, $res[0]); } else { if ($res === false) { return array(-1, "error"); } else { return array(0, 'no result' . $sql); } } break; case 'set': list($ret, $msg) = geocoder('get', array('address' => $data['address'])); if ($ret == 0) { $sql = sprintf("Insert_ID into \"geocoder\" (\"address\",\"lat\",\"lng\",\"is_tw\",\"exact\",\"faddr\",\"name\") values ('%s',%f,%f,%d,%d,'%s','%s')", $data['address'], $data['lat'], $data['lng'], $data['is_tw'], $data['exact'], $data['faddr'], $data['name']); } else { if ($ret == 1) { $sql = sprintf("update \"geocoder\" set \"address\"='%s',\"lat\"=%f, \"lng\"=%d, \"is_tw\"=%d, \"exact\"=%d, \"faddr\"='%s', \"name\"='%s'", $data['address'], $data['lat'], $data['lng'], $data['is_tw'], $data['exact'], $data['faddr'], $data['name']); } else { return array($ret, $msg); } } $res = $db->Execute($sql); logsql($sql, $res); if ($res == true) { return array(1, "ok {$sql}"); } break; } return array(0, "no set / get "); }
ajaxerr("insufficent parameters"); } $da = json_decode($data, true); $mem = new Memcached(); $mem->addServer('localhost', 11211); $key = md5($data['address']); switch ($op) { case 'get': // 查詢結果, 如果沒有設定 memcache, 當作加入 cache 的依據 list($result, $msg) = geocoder($op, $da); if ($result == 0) { $mem->set($key, $data['address'], 3600); ajaxerr($msg); } else { ajaxok($msg); } break; case 'set': if ($mem->get($key) == $data['address']) { list($result, $msg) = geocoder($op, $da); if ($result > 0) { $mem->delete($key); ajaxok($msg); } else { ajaxerr($msg); } } else { ajaxerr("you can't update cache"); } break; }
/** * Compute the GeoJSON features array. * * @return array * The geojson array. */ protected function getGeojsonFeatures() { $features = array(); foreach ($this->getOption('fields', array()) as $field) { $feature = array('type' => 'Feature'); if (isset($field['title']) && !empty($field['title'])) { $feature['properties']['name'] = $field['title']; } if (isset($field['description']) && !empty($field['description'])) { $feature['properties']['description'] = $field['description']; } $json = FALSE; if (isset($field['wkt']) && !empty($field['wkt'])) { geophp_load(); $geophp = \geoPHP::load($field['wkt'], 'wkt'); if (is_object($geophp)) { $json = $geophp->out('json'); } } else { if (isset($field['address']) && !empty($field['address'])) { $geocoder = geocoder($this->getOption('geocoder_handler', 'google'), $field['address'], array(), $this->getOption('geocoder_cache', 2)); if (is_object($geocoder)) { $json = $geocoder->out('json'); } } } if ($json) { $feature['geometry'] = json_decode($json, TRUE); $features[] = $feature; } } return $features; }