Problem in getting GPS Position



  • Hi,

    i am having a problem with getting GPS position My Code is as Below,
    i am able to get into the If(locationDataSource)
    {
    }
    Some Times i get the Location But some times it just dose not respond
    How can i throw an error when locationDataSource->startUpdates(); is not responding.

    Thanks,

    @void MyThread::run()
    {

    // call initialisation of GPS
    
    
     startGPS();
    
     this->exec();
    

    }

    void MyThread::startGPS()
    {
    // Obtain the location data source if it is not obtained already
    if (!locationDataSource)
    {
    locationDataSource = QGeoPositionInfoSource::createDefaultSource(this);

        ReturnResult="In function StartGPS";
        emit GotGPSPositions(ReturnResult);
        
        if (locationDataSource)
        {
            // Whenever the location data source signals that the current
            // position is updated, the positionUpdated function is called
            ReturnResult="Got Location Datasource";
            emit GotGPSPositions(ReturnResult);
            connect(locationDataSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
                          this, SLOT(positionUpdated(QGeoPositionInfo)),Qt::DirectConnection);
    
            // Start listening for position updates
            locationDataSource->startUpdates();
        }
        
        else
        {
            ReturnResult="Unable to get GPS location";
            emit GotGPSPositions(ReturnResult);
            exit(0);
        }
    }
    else
    {
        // Start listening for position updates
        locationDataSource->startUpdates();
    }
    

    }

    void MyThread::positionUpdated(QGeoPositionInfo geoPositionInfo)
    {
    ReturnResult="In Position Update";
    emit GotGPSPositions(ReturnResult);

    if (geoPositionInfo.isValid())
    {        
        // We've got the position. No need to continue the listening.
        locationDataSource->stopUpdates();
        ReturnResult="Position Got";
        emit GotGPSPositions(ReturnResult);
    
        // Save the position information into a member variable
        myPositionInfo = geoPositionInfo;
    
        // Get the current location as latitude and longitude
        QGeoCoordinate geoCoordinate = geoPositionInfo.coordinate();
        qreal latitude = geoCoordinate.latitude();
        qreal longitude = geoCoordinate.longitude();        
        ReturnResult=QString("%1::%2").arg(latitude).arg(longitude);
        GPSLocation=QString("%1::%2").arg(latitude).arg(longitude);
        emit GotGPSPositions(ReturnResult);
        Test();
    }
    else
    {
         ReturnResult="GPS Position is not valid.";
         emit GotGPSPositions(ReturnResult);
         this->exit(0);
    }
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.