Welcome Guest, Not a member yet? Register   Sign In
How to using infowindow_content for direct link to another web?
#5

[eluser]weboap[/eluser]
the long answer is (if somebody need help implementing this lib).


sample db table:

Code:
CREATE TABLE IF NOT EXISTS `mymap` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `place` varchar(50) NOT NULL,
  `desc` varchar(150) NOT NULL,
  `lat` float NOT NULL,
  `lng` float NOT NULL,
  `url` varchar(150) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `mymap`
--

INSERT INTO `mymap` (`id`, `place`, `desc`, `lat`, `lng`, `url`) VALUES
(1, 'Some place 1', 'Some desc 1', 37.429, -122.152, 'www.google.com'),
(2, 'Some place 2', 'Some desc 2', 37.409, -122.132, 'www.google.com');

model : mymap_model.php

Code:
class mymap_model extends CI_Model {

    
    
public function getAllMarkers() {
    
    $query = $this->db->get( 'mymap' );

    if( $query->num_rows() > 0 ) {
        return $query->result();
    } else {
        return false;
    }
    }
    
    
    
    
    
    
    
    
}


controller : mymap.php


Code:
class Mymap extends CI_Controller {
  
  
  function __construct()
  {
  
    parent::__construct();
    

  }
  
  function index(){
    //using data from demo
    // http://biostall.com/demos/google-maps-v3-api-codeigniter-library/multiplemarkers
    
    $this->load->library('googlemaps');

    //can be setup in a config file or after you pull data, use the 1st record  in the set as a center
    //then initialize ....whatever you need to do...

    $config['center'] = '37.4419, -122.1419';
    $config['zoom'] = 'auto';

    $this->googlemaps->initialize($config);
    
    
    $this->load->model('mymap_model', 'mymap');
  
    
  
    $db_markers = $this->mymap->getAllMarkers();
    
    if( $db_markers ){
        
        
        foreach( $db_markers as $db_marker ){
            
        $marker = array();
        $marker['position'] = $db_marker->lat.', '.$db_marker->lng;
        $marker['infowindow_content'] = '<a >url.'\"<b>'.$db_marker->place.'</b></a><br>'.$db_marker->desc;
        $marker['icon'] = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|9999FF|000000';
        $this->googlemaps->add_marker($marker);
        
        }
      
       $data['map'] = $this->googlemaps->create_map();
        
    }else{
        
        $data['map'] = false;
        
    }
  
    $this->load->view('mymap_view.php', $data);
  
  }
  

  
  
}


view: mymap_view.php


Code:
&lt;?php
    if(!$map){
        echo "no data available!";
    }else{
        
        ?&gt;

&lt;html&gt;
&lt;head&gt;&lt;?php echo $map['js']; ?&gt;&lt;/head&gt;
&lt;body&gt;&lt;?php echo $map['html']; ?&gt;&lt;/body&gt;
&lt;/html&gt;

&lt;?
}
?&gt;


hope it help somebody.



Messages In This Thread
How to using infowindow_content for direct link to another web? - by El Forum - 05-14-2012, 03:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB