I have made a site with codeigniter and am using the googlemaps v3 library to add markers to a map. I get the locations from my database as an array of objects, which I then loop through in a foreach adding the location to the map each time. If i enter a string as the infowindow_content everything is fine and the info bubble pops up with the string in when a marker is clicked. When I use a property of the location object though the map doesn’t load.
Here is some example code:
$this->load->library('Googlemaps');
$towers = $this->towers_model->get_towers();
$config['center'] = '18.557394170647473, -9.31640625';
$config['zoom'] = '2';
$this->googlemaps->initialize($config);
foreach($towers as $tower) {
$marker = array();
$marker['position'] = $tower->Lat.', '.$tower->Long;
$marker['infowindow_content'] = '<p>'.$tower->Dedicn.'</p>';
$marker['icon'] = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|9999FF|000000';
$this->googlemaps->add_marker($marker);
}
$this->data['map'] = $this->googlemaps->create_map();
$this->template->write('scripts', $this->data['map']['js']);
$this->template->write_view('content', 'towers/view_all', $this->data);
$this->template->render();
As you can see I am trying to output $tower->Dedicn and when I do the map just won’t load. I have echoed it out thought and its definately defined and contains content etc etc.
Ahhh I found out why! It’s because some of the results had speech marks in them which interfered with the javascript so had to use str_replace to replace ” with \” to escape them!