Welcome Guest, Not a member yet? Register   Sign In
Load items once in controller and not have to reload them.
#1

[eluser]maddtechwf[/eluser]
I'm using a Google Maps plugin that someone developed for CodeIgniter and everything works great. The only thing I'm trying to figure out is how I might be able to do something.

I have an index function that loads all the necessary configuration items for the map to show on the page. I would like to write a few functions that allow me to update just the points on the page instead of having to redraw the map each time.

I know this is more suited for the person that developed this but they don't have a forum to ask questions and they are over sea's so responses are delayed when I have emailed them in the past. Actually, it's been about a week since I last emailed them and no response yet.

Below is my controller and function, I will gladly explain anything to anyone if they have questions. I've tried to document the code as best as I can.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Map extends CI_Controller {
public function index()
{
     //Load Google Maps Library
  $this->load->library('googlemaps');
        
        //Load Map Model
        $this->load->model('map_model');
        
        //Initialize Config Array
        $config = array();
        
        //Set Config array properties
        $config['apiKey'] = '<omitted>';
        $config['center'] = '<omitted>';
        $config['zoom'] = 'auto';
        $config['map_height'] = '920px';
        $config['directions'] = TRUE;
        $config['zoomControlPosition'] = 'BOTTOM_RIGHT';
        $config['zoomControlStyle'] = 'SMALL';
        $config['disableNavigationControl'] = TRUE;
        $config['mapTypeControlPosition'] = 'BOTTOM_LEFT';

        //Initialize GoogleMap and pass Config file
        $this->googlemaps->initialize($config);
        
        //Get co-ordinates from db
        $coords = $this->map_model->get_coordinates();
        
        //Loop through coordinates
        foreach($coords as $coordinate)
        {
            $address_temp = '<table><tr><td>'.$coordinate->Address1.'</td></tr><tr><td>'.$coordinate->City.','.$coordinate->State.' '.$coordinate->Zip.'</td></tr></table>';
            $marker = array();
            $marker['position'] = $coordinate->Lat.','.$coordinate->Long;
            $marker['infowindow_content'] = $coordinate->Name.'<br /><br />'.$coordinate->Address1.'<br />'.$coordinate->City.','.$coordinate->State.' '.$coordinate->Zip;
            $marker['onclick'] = 'detail-card';
            $this->googlemaps->add_marker($marker);
        }
        
        $data['University_Categories'] = $this->map_model->get_categories('University');
        $data['City_Categories'] = $this->map_model->get_categories('City');
        
        // Create Map and store in data variable
        $data['map'] = $this->googlemaps->create_map();
        
        //Set main_content to map view
        $data['main_content'] = "map_view";
        
        //Load Welcome view and pass data
        $this->load->view('includes/template', $data);
}
}
#2

[eluser]jairoh_[/eluser]
create a function w/ params w/ default values and transfer that index codes there. And if you want to show default map in the first page, all you have to do it call the function w/ default input. and if you want to change the map location anytime, make a form and call the function again. Smile




Theme © iAndrew 2016 - Forum software by © MyBB