I'am triying to get the results of a googlemap function, from the javascript code back to the c++ source code in order to process those results. But no success.
I have an html page which I load inside a class derived from QWebView. The html page I load inside the WebView is:
<script src="http://maps.google.com/maps?file=api&v=2&key=GOOGLE_MAPS_KEY"
type="text/javascript"></script>
<script type="text/javascript">
var map;
var geocoder;
var Lat,Lng;
function initialize()
{
if (GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("map"));
//
map.addControl(new GSmallMapControl);
map.addControl(new GMapTypeControl);
geocoder = new GClientGeocoder();
map.setCenter( new GLatLng(0,0),1 );
GEvent.addListener(map, "click", getAddress);
}
}
function getAddress(overlay, latlng) {
if (latlng != null) {
address = latlng;
geocoder.getLocations(latlng, showAddress);
}
}
function showAddress(response) {
map.clearOverlays();
if (!response || response.Status.code != 200) {
alert("Status Code:" + response.Status.code);
} else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(
'<b>orig latlng:</b>' + response.name + '<br/>' +
'<b>latlng:</b>' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '<br>' +
'<b>Status Code:</b>' + response.Status.code + '<br>' +
'<b>Status Request:</b>' + response.Status.request + '<br>' +
'<b>Address:</b>' + place.address + '<br>' +
'<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
'<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
Lat = place.Point.coordinates[1];
Lng = place.Point.coordinates[2];
Name= plcae.AddressDetails.Country.AdmninistrativeArea.Locality;
Map.setValues(Lat, Lng, Name);
}
}
function Open(x,y)
{
map.setCenter( new GLatLng(x,y),13 );
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()" topmargin="0" leftmargin="0">
<div id="map" style="width: 341px; height: 271px"></div>
</body>
</html>
<script src="http://maps.google.com/maps?file=api&v=2&key=GOOGLE_MAPS_KEY"
type="text/javascript"></script>
<script type="text/javascript">
var map;
var geocoder;
var Lat,Lng;
function initialize()
{
if (GBrowserIsCompatible())
{
map = new GMap2(document.getElementById("map"));
//
map.addControl(new GSmallMapControl);
map.addControl(new GMapTypeControl);
geocoder = new GClientGeocoder();
map.setCenter( new GLatLng(0,0),1 );
GEvent.addListener(map, "click", getAddress);
}
}
function getAddress(overlay, latlng) {
if (latlng != null) {
address = latlng;
geocoder.getLocations(latlng, showAddress);
}
}
function showAddress(response) {
map.clearOverlays();
if (!response || response.Status.code != 200) {
alert("Status Code:" + response.Status.code);
} else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(
'<b>orig latlng:</b>' + response.name + '<br/>' +
'<b>latlng:</b>' + place.Point.coordinates[1] + "," + place.Point.coordinates[0] + '<br>' +
'<b>Status Code:</b>' + response.Status.code + '<br>' +
'<b>Status Request:</b>' + response.Status.request + '<br>' +
'<b>Address:</b>' + place.address + '<br>' +
'<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
'<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
Lat = place.Point.coordinates[1];
Lng = place.Point.coordinates[2];
Name= plcae.AddressDetails.Country.AdmninistrativeArea.Locality;
Map.setValues(Lat, Lng, Name);
}
}
function Open(x,y)
{
map.setCenter( new GLatLng(x,y),13 );
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()" topmargin="0" leftmargin="0">
<div id="map" style="width: 341px; height: 271px"></div>
</body>
</html>
To copy to clipboard, switch view to plain text mode
In my c++ code I have
this->page()->mainFrame()->addToJavaScriptWindowObject("Map", this);
connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
this, SLOT(populateJavaScriptWindowObject()));
.....
{
clearCoordinates();
// qDebug()<<"Map finding..."<<local;
QString requestStr
( tr
("http://maps.google.com/maps/geo?q=%1&output=%2&key=%3") .arg(local)
.arg("csv")
.arg("GOOGLE_MAPS_KEY") );
manager->get( QNetworkRequest(requestStr) );
++pendingRequests;
}
...
void Map::populateJavaScriptWindowObject()
{
this->page()->mainFrame()->addToJavaScriptWindowObject("Map", this);
}
{
lat = latitude.toDouble();
lon = longitude.toDouble();
name = n;
qDebug()<<"MAP new values available";
}
this->page()->mainFrame()->addToJavaScriptWindowObject("Map", this);
connect(page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
this, SLOT(populateJavaScriptWindowObject()));
.....
void Map::geoCode(QString local)
{
clearCoordinates();
// qDebug()<<"Map finding..."<<local;
QString requestStr( tr("http://maps.google.com/maps/geo?q=%1&output=%2&key=%3")
.arg(local)
.arg("csv")
.arg("GOOGLE_MAPS_KEY") );
manager->get( QNetworkRequest(requestStr) );
++pendingRequests;
}
...
void Map::populateJavaScriptWindowObject()
{
this->page()->mainFrame()->addToJavaScriptWindowObject("Map", this);
}
void Map::setValues(const QString &latitude, const QString &longitude, const QString &n)
{
lat = latitude.toDouble();
lon = longitude.toDouble();
name = n;
qDebug()<<"MAP new values available";
}
To copy to clipboard, switch view to plain text mode
So, I am expecting that when I click on a point in the google map the javascript calls the object Map, which I exported with the addToJavaScriptWindowObject.
But, nothing: I double click on a point, the map change but it seems that the setValues faunction is not call at all.
Bookmarks