Open GoogleCodeExporter opened 8 years ago
same with ubuntu 12.04
Qt reveals; "JSon Scanner::yylex - unknown char, returning -1" upon trying to
search for a postal address.
Original comment by Josef.Pr...@gmail.com
on 16 Feb 2014 at 1:16
update: Google error, reports that the program is trying to use automated
requests.. gives link to https://support.google.com/websearch/answer/86640
Original comment by Josef.Pr...@gmail.com
on 16 Feb 2014 at 1:29
I believe I am experiencing a similar issue here.
It took me some time to get QJson running (see my comment at
http://code.google.com/p/qt-google-maps/wiki/HowToCompileProject ) and getting
a API key (apparently Google did some changes to their console ).
In the end, I got it running as a "API Key for server apps" with "Any IP
allowed".
Now, the program runs and at the start the "Google Maps Browser" shows a map.
Nice, I was very happy :-)
But as soon as I enter a postal address and press "Go", I get a "Geocode Error"
telling me "Cannot convert to QJson object" (see attached screenshot).
My assumption is that the qt-google-maps program sends out a Json-request to
Google Maps, but gets this error back from Google saying "Sorry can't process
request".
This baffles me, as when I go to my developers-account at Google, they tell me
that they received 4 requests for the API, so this means they have definitely
received my requests, and I am far from over my quota.
Still, maybe I did something wrong with registering my API key?
Or a miscommunication between qt-google-maps and QJson ??
If any additional information is needed, please let me know and I will provide.
The console gives me the following output:
URL = QUrl(
"http://maps.google.com/maps/geo?q=Berwang,+Austria&key=AIzaSyB6P_WbiYJfC3lVgMA4
bGr8jpeBFa-OEvY&output=json&oe=utf8&sensor=false" )
json_parser - syntax error found, forcing abort, Line 1 Column 1
Kind greetings,
Wim
Original comment by zerped...@gmail.com
on 5 Mar 2014 at 9:40
Attachments:
Okay, interesting update:
I tried the QUrl in my browser and trimmed it to simply
http://maps.google.com/maps/geo?q=Berwang,+Austria .
Now, the result is quite interesting:
{
"Status": {
"code": 610,
"request": "geocode",
"error_message": "The Geocoding API v2 has been turned down on September 9th, 2013. The Geocoding API v3 should be used now. Learn more at https://developers.google.com/maps/documentation/geocoding/"
}
}
Apparently, the qt-google-maps program uses the "old" v2 of the Geocoding API,
and should now use v3.
Okay, I will try to solve this this evening and when I manage to succeed, I
will post the results.
Kind greetings,
Wim (vvim)
Original comment by zerped...@gmail.com
on 5 Mar 2014 at 9:43
Guess I found a solution and turned the API from v2 to v3 by doing the
following:
1. change the URL:
in "geocode_data_manager.cpp", function void
GeocodeDataManager::getCoordinates(const QString& address), change the url to:
QString url = QString("https://maps.googleapis.com/maps/api/geocode/json?address=%1&key=%2&oe=utf8&sensor=false").arg(address).arg(apiKey);
for the google_maps.html, you do not have to change the url.
2. change the code of the function "void
GeocodeDataManager::replyFinished(QNetworkReply* reply)" in the file
"geocode_data_manager.cpp" to the following
void GeocodeDataManager::replyFinished(QNetworkReply* reply)
{
QString json = reply->readAll();
qDebug() << "Reply = " << json;
qDebug() << "URL = " << reply->url();
QString strUrl = reply->url().toString();
QJson::Parser parser;
bool ok;
// json is a QString containing the data to convert
QVariant result = parser.parse (json.toLatin1(), &ok);
if(!ok)
{
emit errorOccured(QString("Cannot convert to QJson object: %1").arg(json));
return;
}
/* old version of Geocoding API Application v2
int code = result.toMap()["Status"].toMap()["code"].toInt();
if(code != 200)
{
emit errorOccured(QString("Code of request is: %1").arg(code));
return;
}
*/
// <vvim> upgrade to v3
if(result.toMap()["status"].toString() != "OK")
{
emit errorOccured(QString("Code of request is: %1").arg(result.toMap()["status"].toString()));
return;
}
// </vvim>
/* old version of Geocoding API Application v2
QVariantList placeMarks = result.toMap()["Placemark"].toList();
if(placeMarks.count() == 0)
{
emit errorOccured(QString("Cannot find any locations"));
return;
}
double east = placeMarks[0].toMap()["Point"].toMap()["coordinates"].toList()[0].toDouble();
double north = placeMarks[0].toMap()["Point"].toMap()["coordinates"].toList()[1].toDouble();
emit coordinatesReady(east, north);
*/
// <vvim> upgrade to v3
QVariantList nestedList = result.toMap()["results"].toList();
QVariantList::Iterator it = nestedList.begin();
if(it == nestedList.end())
{
emit errorOccured(QString("Cannot find any locations"));
return;
}
QVariantMap locationOfResult = (*it).toMap()["geometry"].toMap()["location"].toMap();
qDebug() << "location" << locationOfResult["lng"].toDouble() << locationOfResult["lat"].toDouble();
emit coordinatesReady(locationOfResult["lng"].toDouble(), locationOfResult["lat"].toDouble()); // <vvim: handel omdraaien :-) eerst lng dan lat>
// </vvim>
}
// warning: not extensively bug-tested, any comments welcome!!!
// For example: when Google Maps returns several results, only the first
location will be taken (but I believe that is the way the original code works
as well)// If I am granted access to the git, I am very willing to upload this
.cpp for use
Original comment by zerped...@gmail.com
on 7 Mar 2014 at 6:18
This app is no longer working. I did everything the post above mine said but
now i get an error "Cannot convert QJson object: " if anyone could provide any
help i would be grateful!
Original comment by geo.i...@gmail.com
on 25 Aug 2014 at 2:32
Adding to "zerped" changes (which have help immensely may i add, thank you very
much zerped), some people may have issues where their google maps API key isnt
valid.
I found that if you change the line (as modified by zerped):
QString url = QString("https://maps.googleapis.com/maps/api/geocode/json?address=%1&key=%2&oe=utf8&sensor=false").arg(address).arg(apiKey);
too this instead: (simply removing the key)
QString url = QString("https://maps.googleapis.com/maps/api/geocode/json?address=%1&oe=utf8&sensor=false").arg(address);
the map will now be able to goto the typed location, and add a marker there too.
Original comment by russellc...@gmail.com
on 7 Mar 2015 at 1:43
Original issue reported on code.google.com by
animecom...@gmail.com
on 13 Nov 2013 at 12:29