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. Need help in Mobility API
QtWS25 Last Chance

Need help in Mobility API

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 2.5k Views
  • 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.
  • D Offline
    D Offline
    doforumda
    wrote on last edited by
    #1

    hi i am trying and example on this link "Your text to link here...":http://www.forum.nokia.com/document/Mobile_Hands-on_Labs/Qt/MobilityLocation/03_01.html. When i run this code it does not give any errors but it also does not run properly. It does not show location as well as does not fetch maps from google maps. I am trying this in Qt Simulator
    here is the complete code
    mainwindow.h
    @
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QWidget>
    #include <QGeoPositionInfoSource>
    #include <QPointer>
    #include <QtNetwork/QNetworkAccessManager>
    #include <QtNetwork/QNetworkReply>

    QTM_USE_NAMESPACE

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void paintEvent(QPaintEvent *);

    public slots:
    void positionUpdated(QGeoPositionInfo geoPositionInfo);
    void handleNetworkData(QNetworkReply* reply);

    private:
    Ui::MainWindow *ui;
    QGeoPositionInfo myPositionInfo;
    QPointer<QGeoPositionInfoSource> locationDataSource;
    QNetworkAccessManager m_networkAccessManager;
    QPixmap m_mapPixmap;
    void startGPS();
    void fetchMap(const QSize& size,qreal latitude, qreal longitude);

    };

    #endif // MAINWINDOW_H
    @

    mainwindow.cpp
    @
    #include <qgeocoordinate.h>
    #include <QtNetwork/QNetworkRequest>
    #include <QtGui/QImage>
    #include <QtGui/QPixmap>
    #include <QtGui/QPainter>
    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    setWindowTitle("Location API Example");
    connect(&m_networkAccessManager, SIGNAL(finished(QNetworkReply
    )),
    this,
    SLOT(handleNetworkData(QNetworkReply*)));
    startGPS();
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::startGPS()
    {
    if(!locationDataSource) {
    locationDataSource =
    QGeoPositionInfoSource::createDefaultSource(this);
    connect(locationDataSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
    this, SLOT(positionUpdated(QGeoPositionInfo)));
    locationDataSource->startUpdates();
    }
    }

    void MainWindow::positionUpdated(QGeoPositionInfo geoPositionInfo)
    {
    if(geoPositionInfo.isValid()) {
    locationDataSource->stopUpdates();

        myPositionInfo = geoPositionInfo;
    
        QGeoCoordinate geoCoordinate = geoPositionInfo.coordinate();
        qreal latitude = geoCoordinate.latitude();
        qreal longitude = geoCoordinate.longitude();
    
        fetchMap(size(), latitude, longitude);
    }
    

    }

    void MainWindow::fetchMap(const QSize &size, qreal latitude, qreal longitude)
    {
    const QString GOOGLE_MAPS_URL_TEMPLATE =
    "http://maps.google.com/maps/api/staticmap?center=%1,%2&zoom=12&size=%3x%4&maptype=mobile&markers=color:red|label:Y|%1,%2&sensor=false";
    QUrl url = QUrl(GOOGLE_MAPS_URL_TEMPLATE.arg(
    QString::number(latitude), QString::number(longitude),
    QString::number(size.width()),QString::number(size.height())));
    QNetworkRequest request;
    request.setUrl(url);
    }

    void MainWindow::handleNetworkData(QNetworkReply *reply)
    {
    QImage image;
    if(reply->error() == QNetworkReply::NoError) {
    image.load(reply, 0);
    if(!image.isNull()) {
    m_mapPixmap = QPixmap::fromImage(image);
    }
    }
    reply->deleteLater();
    update();
    }

    void MainWindow::paintEvent(QPaintEvent *)
    {
    QPainter painter(this);
    painter.drawPixmap(0, 0, m_mapPixmap);
    }
    @

    main.cpp
    @
    #include <QtGui/QApplication>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    #if defined(Q_WS_S60)
    w.showMaximized();
    #else
    w.show();
    #endif

    return a.exec(&#41;;
    

    }
    @

    .pro file
    @
    #-------------------------------------------------

    Project created by QtCreator 2010-10-25T10:48:01

    #-------------------------------------------------

    QT += core gui network

    TARGET = LocationAPIExample
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui

    CONFIG += mobility
    MOBILITY = location

    symbian {
    #TARGET.UID3 = 0xeeeb9964
    TARGET.CAPABILITY += NetworkServices
    Location
    #TARGET.EPOCSTACKSIZE = 0x14000
    #TARGET.EPOCHEAPSIZE = 0x020000 0x800000
    }
    @

    please help how can i make this code working

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kamalakshantv
      wrote on last edited by
      #2

      Have you debugged and checked if the map is being fetched

      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