Need help in Mobility API
-
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_OBJECTpublic:
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();
#endifreturn a.exec();
}
@.pro file
@
#-------------------------------------------------Project created by QtCreator 2010-10-25T10:48:01
#-------------------------------------------------
QT += core gui network
TARGET = LocationAPIExample
TEMPLATE = appSOURCES += main.cpp
mainwindow.cppHEADERS += mainwindow.h
FORMS += mainwindow.ui
CONFIG += mobility
MOBILITY = locationsymbian {
#TARGET.UID3 = 0xeeeb9964
TARGET.CAPABILITY += NetworkServices
Location
#TARGET.EPOCSTACKSIZE = 0x14000
#TARGET.EPOCHEAPSIZE = 0x020000 0x800000
}
@please help how can i make this code working
-
Have you debugged and checked if the map is being fetched