]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/gps.cxx
As discussed on the mailing list, make the 'nearest' GPS command use scratch lat...
[flightgear.git] / src / Instrumentation / gps.cxx
index 43646cbf0e9e2ab815a49058220fd0d1d3cda8b7..57b67b455a65f5e3bfd70685e6e935610787f693 100644 (file)
@@ -281,6 +281,7 @@ GPS::Config::setExternalCourse(double aCourseDeg)
 ////////////////////////////////////////////////////////////////////////////
 
 GPS::GPS ( SGPropertyNode *node) : 
+  _selectedCourse(0.0),
   _dataValid(false),
   _lastPosValid(false),
   _mode("init"),
@@ -559,6 +560,9 @@ GPS::update (double delta_time_sec)
   if (_dataValid && (_mode == "init")) {
     // allow a realistic delay in the future, here
     SG_LOG(SG_INSTR, SG_INFO, "GPS initialisation complete");
+    
+    _selectedCourse = _config.getExternalCourse();
+    
     if (_route_active_node->getBoolValue()) {
       // GPS init with active route
       SG_LOG(SG_INSTR, SG_INFO, "GPS init with active route");
@@ -1424,10 +1428,15 @@ void GPS::loadNearest()
   int limitCount = _scratchNode->getIntValue("max-results", 1);
   double cutoffDistance = _scratchNode->getDoubleValue("cutoff-nm", 400.0);
   
-  clearScratch(); // clear now, regardless of whether we find a match or not
+  SGGeod searchPos = _indicated_pos;
+  if (isScratchPositionValid()) {
+    searchPos = _scratchPos;
+  }
   
+  clearScratch(); // clear now, regardless of whether we find a match or not
+    
   _searchResults = 
-    FGPositioned::findClosestN(_indicated_pos, limitCount, cutoffDistance, f.get());
+    FGPositioned::findClosestN(searchPos, limitCount, cutoffDistance, f.get());
   _searchResultsCached = true;
   _searchResultIndex = 0;
   _searchIsRoute = false;
@@ -1488,6 +1497,12 @@ void GPS::search()
   string sty(_scratchNode->getStringValue("type"));
   _searchType = FGPositioned::typeFromName(sty);
   _searchQuery = _scratchNode->getStringValue("query");
+  if (_searchQuery.empty()) {
+    SG_LOG(SG_INSTR, SG_WARN, "empty GPS search query");
+    clearScratch();
+    return;
+  }
+  
   _searchExact = _scratchNode->getBoolValue("exact", true);
   _searchOrderByRange = _scratchNode->getBoolValue("order-by-distance", true);
   _searchResultIndex = 0;