1
GPS 장치는 이미 일부 차량에 고정되어 있으며 값 (예 : 위도와 경도)을 연속적으로 전달하여 해당 값이 데이터베이스 (mongodb)에 저장됩니다. 이제 데이터베이스에있는 좌표를 사용하여 여행 한 총 거리를 계산하려고했습니다.이미 GPS 좌표가 mongodb에 저장되어있는 GPS 총 거리를 계산하는 방법
public function cal_distance_traveled()
{
$this->load->model('general/coordinate');
$radius = 6371; //km
$lat1 = $this->input->post('latitude1');
$lat2 = $this->input->post('latitude2');
$lon1 = $this->input->post('logitude1');
$lon2 = $this->input->post('logitude2');
$latitude1 = deg2rad($x);
$latitude2 = deg2rad($x2);
$latitude = deg2rad($lat2 - $lat1);
$logitude = deg2rad($lon2 - $lon1);
$this->coordinate->convertToGPSFormat()
$a = sin($latitude/2) * sin($latitude/2) + cos($latitude1) * cos($latitude2) * sin($logitude/2) * sin($logitude/2);
$c = 2 * atan2(sqrt($a),sqrt(1-$a));
$d = $radius * $c;
var_dump($d);
header('Content-Type: application/json');
echo json_encode(array('success' => 'TRUE'));
}
model.php :
function insertData($x,$y,$timeStamp)
{
$data = array(
'x' => $this->convertToGPSFormat($x),
'y' => $this->convertToGPSFormat($y),
'time' => $timeStamp
);
$this->mongo_db->insert('coordinate', $data);
}
GPS 장치가 이미 일부 차량 연속적 값 (즉, 위도 및 경도) 때문에 그 값을 전달하는 장치에 고정되고,이 데이터베이스에 저장된 (mongodb). 이제 데이터베이스에있는 좌표를 사용하여 여행 한 총 거리를 계산하려고했습니다. –
편집이 더 적절할 것이라고 생각합니다. –