Show route steps using google API in codeigniter - codeigniter

I am saving latitude and longitude of every 15mins. I need to draw a route with marker of the saved data on google map in codeigniter. Some examples given Start and end points but i need to show my database values on map. Kindly suggest some solutions on this topic.
Controller method:
public function geoLocation(){
$this->load->library('googlemaps');
$config['center'] = '37.4419, -122.1419';
$config['zoom'] = 'auto';
$config['directions'] = TRUE;
$config['directionsStart'] = 'Hadapsar, Pune, India';
//$config['directionsDivID'] = 'swargate, Pune, India';
$config['directionsEnd'] = 'swargate, Pune, India';
$config['directionsStart'] = 'swargate, Pune, India';
//$config['directionsDivID'] = 'swargate, Pune, India';
$config['directionsEnd'] = 'Bavdhan, Pune, India';
$this->googlemaps->initialize($config);
$data['map'] = $this->googlemaps->create_map();
$this->load->view('google-map', $data);
}
my view:
<html>
<head><?php echo $map['js']; ?></head>
<body><?php echo $map['html']; ?></body>
<div id="directionsDiv"></div>
</html>
Check above I have three points: Hadapsar, swargate, Bavdhan. I want to draw route on three stations.

Thanks for using my library. Have you seen waypoints?
https://github.com/BIOSTALL/CodeIgniter-Google-Maps-V3-API-Library/blob/master/application/libraries/Googlemaps.php#L130
This might be what you're looking for. Only other thing I can think of is, don't use directions, use a polyline:
http://biostall.com/demos/google-maps-v3-api-codeigniter-library/polyline

i want same result i have array of directions i want draw route
i choose this code
$this->load->library('googlemaps');
$config['center'] = 'udaipur, rajasthan, india';
$config['zoom'] = 'auto';
$config['directions'] = TRUE;
$config['directionsMode'] = "WALKING";
$config['directionsStart'] = '24.5862087,73.6937057';
$config['directionsWaypointArray'] = array(
"24.5866843,73.6890816",
"24.5878709,73.6878411",
"24.5900044,73.6896301",
"24.5973893,73.6857516"
);
$config['directionsEnd'] = '24.6045763,73.6853708';
$config['directionsDivID'] = 'directionsDiv';
$this->googlemaps->initialize($config);
$data['map'] = $this->googlemaps->create_map();
$this->load->view('welcome_message', $data);

Related

CodeIgniter session is empty

I set a session in a class from libraries. Then I tried to get the value of this session in another class from libraries. The value is empty.
I took a look in CodeIgniter Library to find out what the problem could be and at the some similar topics from StackOverflow but I don't see anything wrong from my end. maybe I am missing something. Please help.
// IN THIS CLASS I SET THE SESSION 'fr_phone'
class Form_submit_fr {
var $CI;
protected $fr_id;
protected $fr_data = array();
public function __construct() {
$this->CI =& get_instance();
if (strpos($this->CI->uri->segment(1),'frid') !== false){
$this->fr_id = (int)str_replace('frid','',$this->CI->uri->segment(1));
$this->fr_data = $this->get_fr_data();
// add the phone to session
if (isset($this->fr_data->city_toll) && $this->fr_data->city_toll != '') {
$fr_phone = $this->fr_data->city_toll;
} else {
$fr_phone = $this->fr_data->city_phone;
}
// here the session is set
$this->CI->session->set_userdata('fr_phone', $fr_phone);
//the result is correct
echo $this->CI->session->userdata('fr_phone') . ' - fr_phone<br>';
}
}
....
}
// IN THIS CLASS I NEED TO GET THIS SESSION 'fr_phone'
class P_details {
protected $page_link;
protected $fr_data;
var $CI;
public function __construct(){
$this->CI =& get_instance();
if ($this->CI->uri->segment(2) == false && $this->CI->uri->segment(3) == false) {
$this->page_link = $this->uri->segment(1)."/";
} else if ($this->CI->uri->segment(1) != false && $this->CI->uri->segment(2) != false && $this->CI->uri->segment(3) == false) {
$this->page_link = $this->CI->uri->segment(1)."/".$this->CI->uri->segment(2)."/";
} else if ($this->CI->uri->segment(1) != false && $this->CI->uri->segment(2) != false && $this->CI->uri->segment(3) != false) {
$this->page_link = $this->CI->uri->segment(1)."/".$this->CI->uri->segment(2)."/";
$this->fr_data = $this->get_fr_data($this->CI->uri->segment(3));
}
$this->CI->load->model('getDetails_model');
}
public function get_p_id($type = '') {
$details_array = $this->CI->getDetails_model->all_details($this->page_link);
if (empty($details_array)) {
return FALSE;
}
else {
$data['fr_phone'] = '';
$data['detail'] = $details_array;
// get phone from session
// here the session is empty
echo $this->CI->session->userdata('fr_phone') . ' - fr_phone<br>';
if ($this->CI->session->userdata('fr_phone')) {
$data['fr_phone'] = $this->CI->session->userdata('fr_phone');
}
if ($this->fr_data != '') {
$data['fr_detail'] = $this->fr_data;
}
return $data;
}
}
...
}
this is my config file:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
this is my autoload file:
$autoload['libraries'] = array('database','session');
I have made the suggested changes in config file for $config['sess_save_path']. thanks a lot. I could see the files in the writable folder and the entries in database when I checked this way as well:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 43200;
$config['sess_save_path'] = APPPATH.'writable';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
Also I used database for session:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 43200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
In both cases the session works if I define a session in Controller in constructor or index function. I can get session in View files and in other Classes but if I set a session under a condition for a specific link then this session is always empty when I want to get it in a class from libraries folder or in view files:
//in controller
if (strpos($this->uri->segment(1),'frid') !== false){
...
$fr_phone = '111-222-3333';
$this->session->set_userdata('fr_phone', $fr_phone);
echo $this->session->userdata('fr_phone') // works
}
When I call this session in a Class from libraries folder, the session is empty: above example for class P_details. And there is no way to get a session that is set in a Class from libraries folder and to get it in Another Class from libraries folder. It is very strange and I cannot get it. Also I tried to get session in a different controller and no success.
i had similar issue with one project. After long try i fix the issue the following way
1) in config.php
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'writable absolute path';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
and created the folder named "writable absolute path" in the root
Hopes this will help
It is very strange but I removed the session from autoload:
$autoload['libraries'] = array('database');
I added session_start(); in controllers and I set the session in a common way:
$_SESSION['fr_phone'] = $fr_phone;
Then I was able to get this value in any files. Is this a bug?
I tried without session_start() by adding $this->load->library('session'); and it did not work.
Can anyone find an answer to this issue?
I am using CodeIgniter 3.0.2

CodeIgniter installation now returns a blank screen

Using XAMPP for running codeigniter getting blank screen everytime in localhost. Other codeigniter project working well
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "";
// The following values can probably stay the same.
$db['default']['hostname'] = "";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$active_group = "default";
$active_record = TRUE;
A blank screen usually means you have missed a " ; " someplace. I would say check your syntax completely. The missing ; might be in your view, controller or in the model. Almost any syntax error can bring you a blank screen

how can i hide controller name from the url in codeigniter

i have both admin panel and also one more front panel.....i have different controller for both and in my routes.php i made changes but because of that some links are not working
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['contact'] = 'site/contact';
$route['events'] = 'site/events';
$route['terms'] = 'site/terms';
$route['privacy'] = 'site/privacy';
$route['newevent'] = 'site/add_event';
$route['(:any)'] = "site/$1";
//$route['(:any)'] = "backos/$1";
$route['listevents'] = 'backos/events';
$route['listwhatsapp'] = 'backos/whatsapp';
$route['add_artist'] = 'backos/add_artist';
$route['add_club'] = 'backos/add_club';
$route['index'] = 'backos/index';
$route['check'] = 'backos/check';
$route['add_event'] = 'backos/add_event';
$route['add_city'] = 'backos/add_city';
$route['add_locality'] = 'backos/add_locality';
//$route['(:any)'] = "backos/$1";
this is my routes.php file.
try this...
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['contact'] = 'site/contact';
$route['events'] = 'site/events';
$route['terms'] = 'site/terms';
$route['privacy'] = 'site/privacy';
$route['newevent'] = 'site/add_event';
$route['listevents'] = 'backos/events';
$route['listwhatsapp'] = 'backos/whatsapp';
$route['add_artist'] = 'backos/add_artist';
$route['add_club'] = 'backos/add_club';
$route['index'] = 'backos/index';
$route['check'] = 'backos/check';
$route['add_event'] = 'backos/add_event';
$route['add_city'] = 'backos/add_city';
$route['add_locality'] = 'backos/add_locality';
// this is a catch all if you don't put it as
// the last one everything else below it wont work!
$route['(:any)'] = "site/$1";

losing quality after adding watermark to the picture

I'm working on a website wich i haven't create/developed
Anyway users can upload image and when they do that , there's a function that create a duplicate of that image with a watermark
But the copy with the watermark has low quality and also it's size is much smaller than original image
I dont see anything lowering the quality , maybe it's how CI watermark works ?!
without watermark
http://img.akstube.ir/images/2013/05/DSC_0168_69_70_tonemapped.jpg
with watermark
http://img.akstube.ir/images/2013/05/irwm_DSC_0168_69_70_tonemapped.jpg
here is the function
function ir_watermark($file,$name='',$rebuild=FALSE)
{
$ci = &get_instance();
$pathinfo = pathinfo($file);
$filename = $pathinfo['basename'];
$path = $pathinfo['dirname'];
$new_image = $path . '/irwm_'. $filename;
$path_to_img = base_url(str_replace(base_path(),'',$new_image));
if ($rebuild == FALSE)
if (file_exists($new_image))
{
if ($ci->uri->segment(1) == 'test')
echo "<img src='{$path_to_img}' />";
return $path_to_img;
}
$config['source_image'] = $file;
$config['new_image'] = $new_image;
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = base_path('/files/transparent_bar.png');
$config['wm_font_path'] = base_path('application/assets/view/tahomabd.ttf');
$config['wm_font_size'] = '8';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'left';
$config['wm_hor_offset'] = '0';
$config['wm_vrt_offset'] = '0';
$ci->image_lib->initialize($config);
$ci->image_lib->watermark();
$config['new_image'] = $config['new_image'];
$config['source_image'] = $config['new_image'];
$config['wm_hor_offset'] = '10';
$config['wm_vrt_offset'] = '2';
$config['wm_overlay_path'] = base_path('/files/akstube_logo6.png');
$ci->image_lib->initialize($config);
$ci->image_lib->watermark();
$config['wm_type'] = 'text';
$config['wm_vrt_offset'] = '-3';
$config['wm_text'] = 'Photo : ' . $name;
$config['wm_text'] = strtoupper($config['wm_text']);
$config['wm_hor_alignment'] = 'right';
$config['wm_hor_offset'] = '-50%';
$ci->image_lib->initialize($config);
$ci->image_lib->watermark();
if ($ci->uri->segment(1) == 'test')
echo "<img src='{$path_to_img}' />";
return $path_to_img;
}
WATERMARK IMAGE
http://akstube.ir/files/akstube_logo6.png
http://akstube.ir//files/transparent_bar.png

Add "latest items by category" block in item view page of K2 component

I am using Joomla! K2 v2.4.1 component on Joomla! v1.5.23. I want to display latest items by category in the item view page, the category being the current one which the current viewed item belongs to.
There are modules which I can use to display most recent items by category but I want to modify item.php and other related files (actually I don't know which files to edit except the item.php template file) to accommodate this requirement. Is it possible to achieve this? If yes, which files do I need to edit and with what code?
Given below is what I think is used to retrieve latest items by category.
class K2ViewLatest extends JView {
function display($tpl = null) {
$mainframe = &JFactory::getApplication();
$params = &JComponentHelper::getParams('com_k2');
$user = &JFactory::getUser();
$cache = &JFactory::getCache('com_k2_extended');
$limit = $params->get('latestItemsLimit',3);
$limitstart = JRequest::getInt('limitstart');
$model = &$this->getModel('itemlist');
$itemModel = &$this->getModel('item');
if($params->get('source')){
$categoryIDs = $params->get('categoryIDs');
if(is_string($categoryIDs) && !empty($categoryIDs)){
$categoryIDs = array();
$categoryIDs[]=$params->get('categoryIDs');
}
$categories = array();
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'tables');
if(is_array($categoryIDs)){
foreach($categoryIDs as $categoryID){
$category = & JTable::getInstance('K2Category', 'Table');
$category->load($categoryID);
if ($category->published && ($category->access <= $user->get('aid', 0))) {
//Merge params
$cparams = new JParameter($category->params);
if ($cparams->get('inheritFrom')) {
$masterCategory = &JTable::getInstance('K2Category', 'Table');
$masterCategory->load($cparams->get('inheritFrom'));
$cparams = new JParameter($masterCategory->params);
}
$params->merge($cparams);
//Category image
if (! empty($category->image)) {
$category->image = JURI::root().'media/k2/categories/'.$category->image;
} else {
if ($params->get('catImageDefault')) {
$category->image = JURI::root().'components/com_k2/images/placeholder/category.png';
}
}
//Category plugins
$dispatcher = &JDispatcher::getInstance();
JPluginHelper::importPlugin('content');
$category->text = $category->description;
$dispatcher->trigger('onPrepareContent', array ( & $category, &$params, $limitstart));
$category->description = $category->text;
//Category K2 plugins
$category->event->K2CategoryDisplay = '';
JPluginHelper::importPlugin('k2');
$results = $dispatcher->trigger('onK2CategoryDisplay', array(&$category, &$params, $limitstart));
$category->event->K2CategoryDisplay = trim(implode("\n", $results));
$category->text = $category->description;
$dispatcher->trigger('onK2PrepareContent', array ( & $category, &$params, $limitstart));
$category->description = $category->text;
//Category link
$link = urldecode(K2HelperRoute::getCategoryRoute($category->id.':'.urlencode($category->alias)));
$category->link = JRoute::_($link);
$category->feed = JRoute::_($link.'&format=feed');
JRequest::setVar('view', 'itemlist');
JRequest::setVar('task', 'category');
JRequest::setVar('id', $category->id);
JRequest::setVar('featured', 1);
JRequest::setVar('limit', $limit);
JRequest::setVar('clearFlag', true);
$category->name = htmlspecialchars($category->name, ENT_QUOTES);
$category->items = $model->getData('rdate');
JRequest::setVar('view', 'latest');
JRequest::setVar('task', '');
for ($i = 0; $i < sizeof($category->items); $i++) {
if ($user->guest){
$hits = $category->items[$i]->hits;
$category->items[$i]->hits = 0;
$category->items[$i] = $cache->call(array('K2ModelItem', 'prepareItem'), $category->items[$i], 'latest', '');
$category->items[$i]->hits = $hits;
}
else {
$category->items[$i] = $itemModel->prepareItem($category->items[$i], 'latest', '');
}
$category->items[$i] = $itemModel->execPlugins($category->items[$i], 'latest', '');
//Trigger comments counter event
$dispatcher = &JDispatcher::getInstance();
JPluginHelper::importPlugin ('k2');
$results = $dispatcher->trigger('onK2CommentsCounter', array ( & $category->items[$i], &$params, $limitstart));
$category->items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
}
$categories[]=$category;
}
}
}
$source = 'categories';
$this->assignRef('blocks', $categories);
} else {
$usersIDs = $params->get('userIDs');
if(is_string($usersIDs) && !empty($usersIDs)){
$usersIDs = array();
$usersIDs[]=$params->get('userIDs');
}
$users = array();
if(is_array($usersIDs)){
foreach($usersIDs as $userID){
$userObject = JFactory::getUser($userID);
if (!$userObject->block) {
//User profile
$userObject->profile = $model->getUserProfile($userID);
//User image
$userObject->avatar = K2HelperUtilities::getAvatar($userObject->id, $userObject->email, $params->get('userImageWidth'));
//User K2 plugins
$userObject->event->K2UserDisplay = '';
if (is_object($userObject->profile) && $userObject->profile->id > 0) {
$dispatcher = &JDispatcher::getInstance();
JPluginHelper::importPlugin('k2');
$results = $dispatcher->trigger('onK2UserDisplay', array(&$userObject->profile, &$params, $limitstart));
$userObject->event->K2UserDisplay = trim(implode("\n", $results));
}
$link = K2HelperRoute::getUserRoute($userObject->id);
$userObject->link = JRoute::_($link);
$userObject->feed = JRoute::_($link.'&format=feed');
$userObject->name = htmlspecialchars($userObject->name, ENT_QUOTES);
$userObject->items = $model->getAuthorLatest(0,$limit,$userID);
for ($i = 0; $i < sizeof($userObject->items); $i++) {
if ($user->guest){
$hits = $userObject->items[$i]->hits;
$userObject->items[$i]->hits = 0;
$userObject->items[$i] = $cache->call(array('K2ModelItem', 'prepareItem'), $userObject->items[$i], 'latest', '');
$userObject->items[$i]->hits = $hits;
}
else {
$userObject->items[$i] = $itemModel->prepareItem($userObject->items[$i], 'latest', '');
}
//Plugins
$userObject->items[$i] = $itemModel->execPlugins($userObject->items[$i], 'latest', '');
//Trigger comments counter event
$dispatcher = &JDispatcher::getInstance();
JPluginHelper::importPlugin ('k2');
$results = $dispatcher->trigger('onK2CommentsCounter', array ( & $userObject->items[$i], &$params, $limitstart));
$userObject->items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
}
$users[]=$userObject;
}
}
}
$source = 'users';
$this->assignRef('blocks', $users);
}
//Look for template files in component folders
$this->_addPath('template', JPATH_COMPONENT.DS.'templates');
$this->_addPath('template', JPATH_COMPONENT.DS.'templates'.DS.'default');
//Look for overrides in template folder (K2 template structure)
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates');
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'templates'.DS.'default');
//Look for overrides in template folder (Joomla! template structure)
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2'.DS.'default');
$this->_addPath('template', JPATH_SITE.DS.'templates'.DS.$mainframe->getTemplate().DS.'html'.DS.'com_k2');
//Assign params
$this->assignRef('params', $params);
$this->assignRef('source', $source);
//Set layout
$this->setLayout('latest');
//Display
parent::display($tpl);
}
}
But this file is somehow used to retrieve items in using menu link. I am sorry if this is not the case.
In order to make this work the way you want you would have to modify the K2 item model. The data you want to display (recent items in category) is not currently being pulled from the database so you'd have to change to model to accommodate that. You would be much better off using the K2 content module to pull the most recent items instead. It wouldn't require hacking any core K2 code.
Also, you really need to update your software. K2 is on v2.5.4 and Joomla is on 2.5.1.

Resources