I don't have a website. I am using Qt and I want to display the map on
my widget, but the slot loadCoordinates doesn't get called ever!
I am missing some point, please help.
P.S. I am not using any key.
[code]
#include "hello.h"
#include <QApplication>
#include <QWebView>
#include <QUrl>
#include <QNetworkReply>
#include <QWebFrame>
using namespace std;
#include <iostream>
QGoogleMapView::QGoogleMapView(QWidget *parent) : QWebView(parent),
pendingRequests(0)
{
manager = new QNetworkAccessManager(this);
geoCode ("");
connect (manager, SIGNAL (finished(QNetworkReply*)), this, SLOT
(replyFinished(QNetworkReply*)));
connect (this, SIGNAL (reloadMap()), this, SLOT
(loadCoordinates()));
}
void QGoogleMapView::geoCode(const QString& address)
{
cout << "\ngeocode\n";
clearCoordinates();
QString requestStr( tr("http://maps.google.com/maps/geo?q=
%1&output=%2&key=%3")
.arg("citibank, singapore")
.arg("csv"));
manager->get (QNetworkRequest (requestStr));
}
void QGoogleMapView::replyFinished (QNetworkReply *reply)
{
cout << "\nreplyfinished\n";
QString replyStr (reply->readAll());
QStringList coordinateStrList = replyStr.split(",");
if (coordinateStrList.size() == 4)
{
QPointF
coordinate( coordinateStrList[2].toFloat(),coordinateStrList[3].toFloat() );
coordinates << coordinate;
}
emit reloadMap();
}
void QGoogleMapView::loadCoordinates()
{
cout << "\nloadcoor";
QStringList scriptStr;
scriptStr
<< "var map = new GMap2(document.getElementById(\"map
\"));"
<< "var bounds = new GLatLngBounds;"
<< "var markers = [];"
<< "map.setCenter( new GLatLng(0,0),1 );";
int num=-1;
foreach( QPointF point, coordinates ) {
scriptStr << QString("markers[%1] = new GMarker(new
GLatLng(%2, %3));")
.arg(++num)
.arg(point.x())
.arg(point.y());
}
scriptStr
<< "for( var i=0; i<markers.length; ++i ) {"
<< " bounds.extend(markers[i].getPoint());"
<< " map.addOverlay(markers[i]);"
<< "}"
<< "map.setCenter(bounds.getCenter());";
this->page()->mainFrame()->evaluateJavaScript(scriptStr.join
("\n"));
}
void QGoogleMapView::clearCoordinates()
{
coordinates.clear();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGoogleMapView w;
w.show();
return a.exec();
}
[/code]
--
You received this message because you are subscribed to the Google Groups
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.