Hi I'm encountering a problem regarding creating a new map upon clicking the marker. So here is the flow that I want:
- Display default google map with markers that I included - I'm okay with this
- Upon clicking of marker I'll create a new map which the markers will be removed then I'll put an overlay image.
So the problem is whenever I click the marker the new map doesn't appear. Here is my code
Controller
public function index()
{
$config = array();
$config['center'] = '**.*******, **.*******';
$config['zoom'] = '6';
$config['map_height'] = "500px";
$this->googlemaps->initialize($config);
$marker = array();
$marker['position'] = "*********";
$marker['onclick'] = "
$.ajax({
url: 'Welcome/new_map',
success: function(data) {
$('#v_map').html(data);
}
});
";
$marker['animation'] = 'DROP';
$this->googlemaps->add_marker($marker);
$marker = array();
$marker['position'] = "*********";
$this->googlemaps->add_marker($marker);
$data['map'] = $this->googlemaps->create_map();
$this->load->view('welcome_message', $data);
}
public function new_map(){
$config = array();
$config['center'] = '**.*******, **.*******';
$config['zoom'] = '6';
$config['map_height'] = "500px";
$this->googlemaps->initialize($config);
$marker = array();
$marker['position'] = "*********";
$marker['onclick'] = "
$.ajax({
url: 'Welcome/new_map',
success: function(data) {
$('#v_map').html(data);
}
});
";
$marker['animation'] = 'DROP';
$this->googlemaps->add_marker($marker);
$marker = array();
$marker['position'] = "*********";
$this->googlemaps->add_marker($marker);
$data['map'] = $this->googlemaps->create_map();
$this->load->view('map_template', $data);
}
View
<html lang="en">
<head>
<?php echo $map['js']; ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div id = "v_map">
<?php echo $map['html']; ?>
</div>
</body>
</html>
map_template
<?php echo $map['html']; ?>
I'm currently trying to fix that the new map will appear before proceeding with the overlay part.
PS. I'm using Biostall's library of Google maps for Codeigniter.