Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Problem in getting GPS Position

Problem in getting GPS Position

Scheduled Pinned Locked Moved Mobile and Embedded
1 Posts 1 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ajayzone
    wrote on last edited by
    #1

    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);
    }
    

    }
    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved