Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

javascript - 从控制器传递纬度和经度,以使用Googlemaps Codeigniter查看(Pass Latitude and Longitude from controller to view with Googlemaps Codeigniter)

Im trying to get the lat nad lng from a draggable marker from my controller,(我正在尝试从控制器的可拖动标记中获取经纬度,)

My Controller function(我的控制器功能) public function addnew(){ // Load the library $this->load->library('googlemaps'); // Load our model $this->load->model('Sedes_model', '', TRUE); // Initialize the map, passing through any parameters $config['center'] = '-17.3718, -66.1615'; $config['zoom'] = "15"; $this->googlemaps->initialize($config); // Get the co-ordinates from the database using our model $sedes = $this->Sedes_model->getCoordanites(); // Loop through the coordinates we obtained above and add them to the map foreach ($sedes as $row) { $marker = array(); $marker['position'] = $row->location; $this->googlemaps->add_marker($marker); } $marker = array(); $marker['position'] = '-17.3718, -66.1615'; $marker['draggable'] = true; $marker['ondragend'] = 'alert('You just dropped me at: ' + event.latLng.lat() + ', ' + event.latLng.lng());'; $this->googlemaps->add_marker($marker); // Create the map $data = array(); $data['map'] = $this->googlemaps->create_map(); print_r($data['map']['markers']); // Load our view, passing through the map data $this->load->view('sedes/add_sede_view', $data); } with this i get my map with some markers from my database and also a draggable marker.(这样我就可以从数据库中获取带有一些标记的地图以及可拖动的标记。) im trying to get the lat and lng from the marker to an input value in my view, right now i get the coordinates in the alert box.(我试图在视图中将纬度和经度从标记获取到输入值,现在我在警报框中获取了坐标。) I think i have to use javascript for this, but i don't really know much of it(我认为我必须为此使用javascript,但我并不是很了解) I really appreciate any help with this.(我对此非常感谢。)   ask by J_Kohlberg translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can pass values from a text input (or any form element) to the controller using $this->input->get('input_name');(您可以使用$ this-> input-> get('input_name');将文本输入(或任何表单元素)中的值传递给控制器??。)

or $this->input->post('input_name');, depending on the method you are using in your form.(或$ this-> input-> post('input_name');,取决于您在表单中使用的方法。) In your controller you should update the $marker['ondraged'] to something like:(在您的控制器中,您应该将$ marker ['ondraged']更新为以下内容:) $marker['ondragend'] = "document.getElementById('position').value = event.latLng.lat() + ', ' + event.latLng.lng() +';"; So, for example you have a form with(因此,例如,您有一个带有) <form method="post" action="<?php echo base_url('update_data'); ?>"> <input type="hidden" id="position" name="latlng" value="" /> <input type="submit" value="send" /> </form> you can receive the data in your controller's method by(您可以通过控制器的方法接收数据) public function update_data() { // use here the $this->input->post('latlng') as needed if($_POST) { $data = array( "latlng" => $this->input->post('latlng') ); $this->load->view('map', $data); } } Code not tested, hope it works ;)(代码未经测试,希望它能起作用;))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...