Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //get latitude and longitude from ui
- latitude = ui->latitude->toPlainText().toDouble();
- longitude = ui->longitude->toPlainText().toDouble();
- //query to get latitude, longitude and template from way_point table in database
- QSqlQuery query1;
- query1.exec("SELECT w, latitude, longitude, template FROM way_point ORDER BY template ASC;");
- //get smallest distance from ui latitude longitude and latitude longitude in database
- double start = 1000000;
- double tmp;
- int template_way, index;
- while (query1.next()){
- tmp = distance_two_point(latitude,longitude,query1.value(1).toDouble(),query1.value(2).toDouble());
- if(start > tmp){
- start = tmp;
- template_way = query1.value(3).toInt();
- index = query1.value(0).toInt();
- }
- }
- //query to get value from two point in database
- QList<double> result;
- QSqlQuery query2;
- query2.prepare(("SELECT r FROM line WHERE template = ? ORDER BY w1 ASC;"));
- query2.addBindValue(template_way);
- query2.exec();
- while (query2.next()) {
- result.append(query2.value(0).toDouble());
- }
- //if template not found in database
- if(result.isEmpty()){
- ui->textEdit->setText("Template not Found");
- } else{
- //get distance from ui latitude longitude to destination point in database
- double sum = start;
- for(int i=index-2;i >= 0;i--){
- sum = sum + result[i];
- }
- //show distance value in KM
- ui->textEdit->setText(QString::number(sum) + " KM to template " + QString::number(template_way));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement