Welcome Guest, Not a member yet? Register   Sign In
GoogleMaps API V3 and CodeIgniter
#1

[eluser]maddtechwf[/eluser]
I've been using a GoogleMaps helper made by Biostall but I can't get a timely reply on some items so I'm hoping that someone on here might be able to help me. They had more to do with CI than the helper anyways.

I have my settings to initialize my map stored in my __construct so that they can be called by any function. Which that works great with my index function but I'm having issues with other functions.

Let say that my url is mysite.com, so when I go to mysite.com/maps/index.php my map comes up just fine but when I navigate to mysite.com/maps/index/Maps/all_points , I get a blank page.

I only have one controller, model, and view. Am I not calling something correctly?
#2

[eluser]boltsabre[/eluser]
Maybe some of your code would help?

What are "Maps/all_points"? Are they set variables of your index function? Are you doing anything with them? Or are they something to do with the helper, I've never used it...
#3

[eluser]maddtechwf[/eluser]
Maps/all_points is a function in my controller that calls a function in my model to get the information for my points for my map.

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

class Map extends CI_Controller {
    //Initialize Config Array
    Var $config = array();
    
    
    
    function __construct()
    {
        parent::__construct();
        
        //Load Google Maps Library
        $this->load->library('googlemaps');
        
        //Load Map Model
        $this->load->model('map_model');
        
        //Set Config array properties
        $config['apiKey'] = '';
        $config['center'] = '';
        $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);
    }
    
public function index()
{
    
        $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);
}

    public function all_points()
    {
        //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);
        }
    }
    
    public function lookup()
    {
        $search_value = $this->input->post('search-item', TRUE);
      
        $results = $this->map_model->search($search_value);
        
        if ( $results->num_rows() > 0 )
        {
            foreach ( $results->result() as $result )
            {
                $marker = array();
                $marker['position'] = $result->Lat.','.$result->Long;
                $this->googlemaps->add_marker($marker);
            }
        }
    }

    public function get_directions()
    {
        $lat_long = $this->form->input();
        $origin = $this->form->input();
        
        $dir_config = array();
        
        $dir_config['directionsStart'] = $origin;
        $dir_config['directionsEnd'] = $lat_long;
        $dir_config['directionsDraggable'] = TRUE;
        $dir_config['directionsUnits'] = 'imperial';
        $dir_config['directionsDivID'] = 'direction-list';
        
        $this->googlemaps->initialize($dir_config);
        
        $data['map'] = $this->googlemaps->create_map();
        
        $data['main_content'] = "map_view";
        $this->load->view('includes/template', $data);
    }
}
#4

[eluser]maddtechwf[/eluser]
Model (Map_model.php)
Code:
&lt;?php
    class Map_model extends CI_Model{
        function __construct()
        {
            parent::__construct();
        }
        
        // param = NULL is to make the parameter optional.
        function get_coordinates($point_id = NULL)
        {
            $return = array();
            $this->db->select("Lat,Long,Name,Address1,City,State,Zip");
            $this->db->from("Points");
            $query = $this->db->get();
            
            if($query->num_rows() > 0)
            {
                foreach ($query->result() as $row){
                    array_push($return, $row);
                }
            }
            
            return $return;
        }
        
      
        //Get points in a specific category
        function get_category_points($category_id)
        {
            $return = array();
            
            //DB Connection
            //$this->db->select('Lat,Long,Name,Address1,City,State,Zip');
            //$this->db->from('Points');
            //$this->db->join('Point2Category','Point2Category.Point_ID = ');
            //$this->db->where('Category_ID='.$category_id);
            //$point_ids = $this-&gt;db-&gt;get();
            
            if ( $point_ids-&gt;num_rows() &gt; 0 )
            {
                foreach ( $point_ids-&gt;result() as $point )
                {
                    $points = get_cordinates($point);
                }
                
                if ($points-&gt;num_rows() &gt; 0)
                {
                    foreach ( $points-&gt;results() as $p )
                    {
                        array_push($return, $p);
                    }
                }
            }
            
            return $return;
        }
        
        //Get Gategories
        function get_categories($cat_type)
        {
            $return = array();
            
            //DB Connection
            $this-&gt;db-&gt;select('ID,Name');
            $this->db->from('Category');
            $this->db->where('Type', $cat_type);
            $category_items = $this->db->get();
            
            if ( $category_items->num_rows() > 0)
            {
                foreach ( $category_items->result() as $item )
                {
                    $return[$item->ID] = $item->Name;
                }
            }
            return $return;
        }
        
        function search($term)
        {
            $return = array();
            
            //DB Connection
            $this->db->select("Lat,Long,Name,Address1,City,State,Zip");
            $this->db->from("Points");
            $this->db->like('Name', $term);
            // $this->db->like('Tags', $term);
            $search_results = $query = $this->db->get();
            
            if ( $search_results->num_rows() > 0 )
            {
                foreach ( $search_results->result() as $result )
                {
                    array_push($return, $result);
                }
            }
            
            return $return;
        }
    }

View (map_view.php)
Code:
&lt;?= anchor('/Map/all_points', 'All Points'); ?&gt;
#5

[eluser]boltsabre[/eluser]
Quote:when I navigate to mysite.com/maps/index/Maps/all_points
Okay, that's your problem, your URL is all messed up! You want to go to
mysite.com/maps/all_points

Fix up your anchor tag in your view file and you should be fine!

Oh wait... you said domain.com/maps/index worked, do you also have another controller called "maps", because in your code above your controller is called "map"...
#6

[eluser]maddtechwf[/eluser]
I actually got my problem fixed by using a different plugin that I found on the CI Plugin repository. https://github.com/EllisLab/CodeIgniter/...V3-Library

I'm getting points loaded on my map with no problem now.

I'm trying to setup a jquery function that will look at an event change on a dropdown and take value of the item selected and pass it to a function to return certain points. Here's an example.

Value Option
====== ==================
1 Food
2 Hotel
3 Sports

I then need to pass that value to a function called GetCordinates($point_id = '');




Theme © iAndrew 2016 - Forum software by © MyBB