Javascript Codeigniter-使用html表单将标记添加到Google地图并存储在数据库中
嗨,我正在尝试建立一个应用程序,使用Codeigniter和谷歌地图。我对两者都是新手,我正试图允许用户使用HTML表单向地图添加标记,然后将其存储在数据库中 我正在使用Codeigniter和谷歌地图库 我使用控制器中的“贴图”函数生成贴图Javascript Codeigniter-使用html表单将标记添加到Google地图并存储在数据库中,javascript,php,codeigniter,google-maps,google-maps-api-3,Javascript,Php,Codeigniter,Google Maps,Google Maps Api 3,嗨,我正在尝试建立一个应用程序,使用Codeigniter和谷歌地图。我对两者都是新手,我正试图允许用户使用HTML表单向地图添加标记,然后将其存储在数据库中 我正在使用Codeigniter和谷歌地图库 我使用控制器中的“贴图”函数生成贴图 public function maps() { $data['title']= 'Maps'; $config['center'] = $_GET['venue_lat'].",". $_GET['venue_long']; $c
public function maps()
{
$data['title']= 'Maps';
$config['center'] = $_GET['venue_lat'].",". $_GET['venue_long'];
$config['height'] = '450px';
$config['width'] = '100%';
$config['zoom'] = '15';
$config['trafficOverlay'] = TRUE;
$config['places'] = TRUE;
$config['placesLocation'] = $_GET['venue_lat'].",". $_GET['venue_long'];
$config['placesRadius'] = 3000;
$config['placesName'] = "church";
$this->googlemaps->initialize($config);
$marker = array();
$marker['position'] = $_GET['venue_lat'].",". $_GET['venue_long'];
$marker['infowindow_content'] = $_GET['venue_name'];
$marker['icon'] = 'http://chart.apis.google.com/chart? chst=d_map_pin_letter&chld=A|9999FF|000000';
$marker['title'] = $_GET['venue_name'];
$this->googlemaps->add_marker($marker);
$data['map'] = $this->googlemaps->create_map();
$this->load->view('include/reviews_header',$data);
$this->load->view('pages/reviews_view.php', $data);
$this->load->view('include/footer',$data);
}
用于添加服务的控制器函数
public function services()
{
$data['title']= 'Services';
$this->load->model('addService_model');
$this->load->helper(array('form', 'url'));
$this->addService_model->new_services();
}
在我的标题中我有
<?php
echo $map['js'];
?>
然后我需要提交表单并将值插入数据库中的服务表中
我不确定的第二个问题是如何在不刷新页面的情况下实现这一点,因为我不想重置$\u Get变量。如果这些变量重置,我会得到未知变量错误
这是我第一次使用Codeigniter、谷歌地图库或谷歌地图API V3,我不知道如何在MVC平台上实现这一点。非常感谢您的帮助。我很久以前就写过类似的文章,可能会对您有所帮助。它可能会给出一些想法,但不是您正在寻找的解决方案。感谢您的回复和演示。这是一个优秀的演示-我看到你有一个标记在地图上时,它是初始化。有很多事情要考虑。出于我的目的,在用户单击地图上的某个位置之前,不会有任何标记,然后该位置将删除标记并在文本框中显示单击点的坐标。用户可以将标记拖放到其最终位置,然后单击“提交”以添加到数据库中。
<?php
echo '<div id="map_canvas">';
echo $map['html'];
echo '</div>';
?>
<form id="add_marker" action='<?php echo site_url("user/services") ?>' method="POST">
<fieldset>
<legend>Add New Marker to Map</legend>
<div class="input">
<label for="name">Service Name</label>
<input type="text" name="service_name"id="name">
</div>
<div class="input">
<label for="address">Service Town</label>
<input type="text" name="service_location"id="address">
</div>
<div class="input">
<label for="address">Service Type</label>
<input type="text" name="service_type"id="type">
</div>
<div class="input">
<label for="address">Service latitude</label>
<input type="text" name="service_lat"id="lat" value="document.getElementById('displayLat').value;">
</div>
<div class="input">
<label for="address">Service longitude</label>
<input type="text"name="service_long"id="long">
</div>
<button type="submit" id="submit_btn">Add Marker</button>
</fieldset>
</form>
<?php
class AddService_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
function new_services()
{
$service_data = array(
'service_name' => $this->input->post('service_name'),
'service_location' => $this->input->post('service_location'),
'service_lat' => $this->input->post('service_lat'),
'service_long' => $this->input->post('service_long'),
'service_type' => $this->input->post('service_type')
);
$this->db->insert('service', $service_data);
}
/*End of file fixture_model.php*/
/*Location .application/models/fixture_model.php*/
?>
$config['onclick'] = 'createMarker_map({ map: map, position:event.latLng }); alert(event.latLng.toString());';