[eluser]Unknown[/eluser]
I have tried this script, but google maps cannot be loaded.
Model:
Code:
<?php
class mymap_model extends CI_Model {
public function getAllMarkers() {
$this->load->database();
$query = $this->db->get('mymap');
if( $query->num_rows() > 0 ) {
return $query->result();
} else {
return false;
}
}
}
?>
Controller
Code:
<?php
class Mymap extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index(){
$this->load->library('googlemaps');
$config['center'] = '37.4419, -122.1419';
$config['zoom'] = 'auto';
$this->googlemaps->initialize($config);
$this->load->model('mymap_model');
$db_markers = $this->mymap_model->getAllMarkers();
if( $db_markers ){
foreach( $db_markers as $db_marker ){
$marker = array();
$marker['position'] = $db_marker->lat.', '.$db_marker->lng;
$marker['infowindow_content'] = $db_marker->place.'\'<b>'.$db_marker->place.'</b><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
Code:
<?php
if(!$map){
echo "no data available!";
}else{
?>
<html>
<head><?php echo $map['js']; ?></head>
<body><?php echo $map['html']; ?></body>
</html>
<?
}
?>
Any help would be greatly appreciated guys