Hi All, I am trying to execute javascript through Qt script. My javascript contains code for google maps API. when i ran it through Qt script, it gives an Error like "Reference Error: google is not defined".
I think the problem is the <script type="text/javascript" src="http://maps.google.com/maps/api/js? sensor=false"> </script> line from the html file. If I use the <> brackets, the java script engine won't compile it, and if I omit the line, the program gets the "google not found" error... Please anyone help me how to call the URL inside <script> tag in javascript which is been executed by Qt script? NOTE: Here, I have included JS and Qt script file. JS file: function calcRoute() { var directionsService = new google.maps.DirectionsService(); // getting error here."google not defined" var start = "chennai"; var end = "bangalore"; var request = { origin:start, destination:end, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(resp, status) { if (status == google.maps.DirectionsStatus.OK) { return resp; } }); } QtScript file: #include <QApplication> #include <QtScript> #include <QScriptEngine> int main(int argc, char **argv) { QApplication app(argc, argv); QScriptEngine engine; QScriptValue global = engine.globalObject(); QString fileName1 = "direction.js"; QFile scriptFile1(fileName1); if(!scriptFile1.open(QIODevice::ReadOnly)) { qDebug() << "error"; } QTextStream stream1(&scriptFile1); QString contents1 = stream1.readAll(); scriptFile1.close(); QScriptValue result1 = engine.evaluate(contents1, fileName1); if(engine.hasUncaughtException()) { int line = engine.uncaughtExceptionLineNumber(); qDebug() << "uncaught exception at line" << line << ":" << result1.toString(); } QScriptValue val1 = global.property("calcRoute"); QScriptValueList args1; QScriptValue final_res1 = val1.call(QScriptValue(), args1); // calling JS function calcRoute with no args qDebug() << "The result is: " << final_res1.toString(); return app.exec(); } -- You received this message because you are subscribed to the Google Groups "Google AJAX APIs" 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-ajax-search-api?hl=en.
