Reference Error: google is not defined

2,685 views
Skip to first unread message

karthick

unread,
Mar 3, 2011, 3:03:23 AM3/3/11
to Google Maps JavaScript API v3
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 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();
}

Rossko

unread,
Mar 3, 2011, 5:05:37 AM3/3/11
to Google Maps JavaScript API v3
> I am trying to execute javascript through Qt script.

For questions about how to use Qt, try here
http://www.qtcentre.org/forum.php

The maps javascript is normally loaded with <script> tag in a webpage

Karthick

unread,
Mar 4, 2011, 4:36:10 AM3/4/11
to google-map...@googlegroups.com, Rossko
@Rossko: does it mean it is loaded in webpage only?
                  is it possible to load maps javascript API on non web browser environment?



--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.




--
Regards,
Karthick












geoco...@gmail.com

unread,
Mar 4, 2011, 8:32:04 AM3/4/11
to Google Maps JavaScript API v3
On Mar 4, 1:36 am, Karthick <sppkarth...@gmail.com> wrote:
> @Rossko: does it mean it is loaded in webpage only?
>                   is it possible to load maps javascript API on non
> web browser environment?

It may be possible, but is against the terms of use.

-- Larry


>
>
>
>
>
>
>
>
>
> On Thu, Mar 3, 2011 at 3:35 PM, Rossko <ros...@culzean.clara.co.uk> wrote:
> > > I am trying to execute javascript through Qt script.
>
> > For questions about how to use Qt, try here
> >http://www.qtcentre.org/forum.php
>
> > The maps javascript is normally loaded with <script> tag in a webpage
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Maps JavaScript API v3" group.
> > To post to this group, send email to
> > google-map...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-maps-js-a...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
> --
> *Regards,*
> *Karthick
> *
Reply all
Reply to author
Forward
0 new messages