Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. //get latitude and longitude from ui
  2. latitude = ui->latitude->toPlainText().toDouble();
  3. longitude = ui->longitude->toPlainText().toDouble();
  4.  
  5. //query to get latitude, longitude and template from way_point table in database
  6. QSqlQuery query1;
  7. query1.exec("SELECT w, latitude, longitude, template FROM way_point ORDER BY template ASC;");
  8.  
  9. //get smallest distance from ui latitude longitude and latitude longitude in database
  10. double start = 1000000;
  11. double tmp;
  12. int template_way, index;
  13. while (query1.next()){
  14. tmp = distance_two_point(latitude,longitude,query1.value(1).toDouble(),query1.value(2).toDouble());
  15. if(start > tmp){
  16. start = tmp;
  17. template_way = query1.value(3).toInt();
  18. index = query1.value(0).toInt();
  19. }
  20. }
  21.  
  22. //query to get value from two point in database
  23. QList<double> result;
  24. QSqlQuery query2;
  25. query2.prepare(("SELECT r FROM line WHERE template = ? ORDER BY w1 ASC;"));
  26. query2.addBindValue(template_way);
  27. query2.exec();
  28. while (query2.next()) {
  29. result.append(query2.value(0).toDouble());
  30. }
  31.  
  32. //if template not found in database
  33. if(result.isEmpty()){
  34. ui->textEdit->setText("Template not Found");
  35. } else{
  36.  
  37. //get distance from ui latitude longitude to destination point in database
  38. double sum = start;
  39. for(int i=index-2;i >= 0;i--){
  40. sum = sum + result[i];
  41. }
  42.  
  43. //show distance value in KM
  44. ui->textEdit->setText(QString::number(sum) + " KM to template " + QString::number(template_way));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement