Results 1 to 2 of 2

Thread: Reference Error: google is not defined

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Reference Error: google is not defined

    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
    Qt Code:
    1. <script type="text/javascript" src="http://maps.google.com/maps/api/js?
    2. sensor=false">
    3. </script>
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. function calcRoute() {
    2. var directionsService = new google.maps.DirectionsService(); //
    3. getting error here."google not defined"
    4. var start = "chennai";
    5. var end = "bangalore";
    6. var request = {
    7. origin:start,
    8. destination:end,
    9. travelMode: google.maps.DirectionsTravelMode.DRIVING
    10. };
    11. directionsService.route(request, function(resp, status) {
    12. if (status == google.maps.DirectionsStatus.OK) {
    13. return resp;
    14. }
    15.  
    16. });
    17. }
    To copy to clipboard, switch view to plain text mode 

    QtScript file:
    Qt Code:
    1. #include <QApplication>
    2. #include <QtScript>
    3. #include <QScriptEngine>
    4.  
    5. int main(int argc, char **argv)
    6. {
    7. QApplication app(argc, argv);
    8. QScriptEngine engine;
    9. QScriptValue global = engine.globalObject();
    10.  
    11. QString fileName1 = "direction.js";
    12. QFile scriptFile1(fileName1);
    13. if(!scriptFile1.open(QIODevice::ReadOnly))
    14. {
    15. qDebug() << "error";
    16. }
    17. QTextStream stream1(&scriptFile1);
    18. QString contents1 = stream1.readAll();
    19. scriptFile1.close();
    20. QScriptValue result1 = engine.evaluate(contents1, fileName1);
    21. if(engine.hasUncaughtException()) {
    22. int line = engine.uncaughtExceptionLineNumber();
    23. qDebug() << "uncaught exception at line" << line << ":" <<
    24. result1.toString();
    25. }
    26. QScriptValue val1 = global.property("calcRoute");
    27. QScriptValueList args1;
    28. QScriptValue final_res1 = val1.call(QScriptValue(), args1); //
    29. calling JS function calcRoute with no args
    30. qDebug() << "The result is: " << final_res1.toString();
    31. return app.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 3rd March 2011 at 13:05. Reason: code tags

Similar Threads

  1. Replies: 3
    Last Post: 15th November 2010, 07:53
  2. Error::defined after prior declaration as dllimport:
    By hasnatzaidi in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2009, 01:37
  3. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 14:28
  4. Undefined Reference error!!!
    By Kapil in forum Newbie
    Replies: 25
    Last Post: 28th March 2006, 12:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.