如何在编码器点火器中将值从控制器发送到模型



在视图文件"(V_tampil_rekomendasi("中,我制作了一个包含函数纬度和经度值的输入文本来检查当前位置。 在结果中,我将其发送到文件控制器并且它起作用了。我使用var_dump功能进行了检查。 但是当我将其(纬度和经度(发送到模型文件(M_Metode(时。缺少纬度和经度的值。 并且V_display_建议中显示的结果丢失或没有要显示的内容。 这是我的视图文件:

<button class="btn btn-primary" onclick="getLocation()">Cek Lokasi Anda</button></p>
<form action="<?php echo base_url().'metode/index'; ?>" method="post">
<div class="row">
<div class="col">
<p class="font-weight-bold">LATITUDE :</p>
<input class="form-control" type = "text" id = "out_latitude" name="latitude_awal" placeholder="Latitude" readonly/>
</div>
<div class="col">
<p class="font-weight-bold">LONGITUDE :</p>
<input class="form-control" type = "text" id = "out_longitude" name="longitude_awal" placeholder="Longitude" readonly/>
</div>
</div>
<br>
<input class="btn btn-primary" type="submit" value="Cari Fotografer">
</form>
<table class="table table-bordered" style="margin:20px auto;" border="1">
<tr>
<thead class="thead-dark">
<th>No</th>
<th>Nama</th>
<th>Alamat</th>
<th>Kamera</th>
<th>Spesifikasi Foto</th>
<th>Jarak</th>
</thead>
</tr>
<?php
$no = 1;
foreach($tb_fotografer as $fg)
{
?>
<tr>
<td><?php echo $no++ ?></td>
<td><?php echo $fg['nama'] ?></td>
<td><?php echo $fg['alamat'] ?></td>
<td><?php echo $fg['kamera'] ?></td>
<td><?php echo $fg['keahlian_foto'] ?></td>
<td><?php echo $fg['distance']?> Km </td>
</tr>
<?php } ?>
</table>

我的Javascript检查当前位置(在视图文件中(:

<script>
var view_lat = document.getElementById("tampilkan_lat");
var view_long = document.getElementById("tampilkan_long");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
view.innerHTML = "Yah browsernya ngga support Geolocation bro!";
}
}
function showPosition(position) {
var var_latitude  = position.coords.latitude;
document.getElementById("out_latitude").value = var_latitude ;
var var_longitude  = position.coords.longitude;
document.getElementById("out_longitude").value = var_longitude ;
}
</script>

这是我的控制器:

function index()
{
$latitude = $this->input->post('latitude_awal');
$longitude = $this->input->post('longitude_awal');
$data_latlong = array(
'latitude_awal' => $latitude,
'longitude_awal' => $longitude);
$data_fotografer= $this->m_metode->tampil_data_fotografer($data_latlong);
$this->load->view('public/pencari/v_tampil_rekomendasi',['tb_fotografer' => $data_fotografer]);
}

这是我的模型:

function tampil_data_fotografer($data_latlong)
{
$latFrom = deg2rad((float)('latitude_awal'));
var_dump($latFrom);
$lonFrom = deg2rad((float)('longitude_awal'));
var_dump($lonFrom);
$data_fg = $this->db->query("SELECT fotografer_id, nama, alamat, kamera, keahlian_foto, latitude, longitude FROM tb_fotografer");
$out = [];
{
foreach($data_fg->result_array() as $row)
{
$keahlianfoto = $row['keahlian_foto'];
$latTo = deg2rad((float)$row['latitude']);
$lonTo = deg2rad((float)$row['longitude']);
$latDelta = $latTo - $latFrom;
$lonDelta = $lonTo - $lonFrom;
$distance = (2 * asin(sqrt(pow(sin($latDelta / 2), 2) + cos($latTo) * cos($latFrom) * pow(sin($lonDelta / 2), 2)))) * 6371;
if ($distance <=1)
{
$out[] = array_merge($row, ['distance' => $distance]);
}
}
}
return $out;
}

有人知道什么问题吗?请帮帮我,谢谢

以下代码(在您的模型中(:

$latFrom = deg2rad((float)('latitude_awal')); // (float)('latitude_awal') = 0
var_dump($latFrom);
$lonFrom = deg2rad((float)('longitude_awal')); // (float)('longitude_awal') = 0
var_dump($lonFrom);

应该是这样的:

$latFrom = deg2rad((float) $data_latlong['latitude_awal']);
$lonFrom = deg2rad((float) $data_latlong['longitude_awal']);

相关内容

  • 没有找到相关文章

最新更新