[SOLVED] QGeoCoordinate returns Nan in iOS



  • Hi , I use qt 5.3.2 on mac to implement an application for iOS. I want to get user current location. My code is here:

    @
    source = QGeoPositionInfoSource::createDefaultSource(this);
    if (source){
    text->append("sourceName: " + source->sourceName()); //return: core location
    source->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);
    source->setUpdateInterval(10000);
    }

    QGeoPositionInfo info = source->lastKnownPosition();
    QGeoCoordinate coordinate = info.coordinate();
    latitude = QString::number(coordinate.latitude());
    longitude = QString::number(coordinate.longitude());
    

    @

    The code works for android but in iOS(iPhone 4s) latitude and longitude are nan.
    in .pro file, i added:
    @
    QT +=positioning
    LIBS += -framework CoreLocation
    @
    What's wrong in my code? please help me.



  • I found my problem. I added a line of code to above function and it works.

    @
    source->setUpdateInterval(10000);
    source->updateRequest(); //this line of code solve my problem
    @


Log in to reply
 

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