Page 1 of 1

Problem with calling google API from server script: "...google is not defined..."

Posted: Fri Jun 26, 2015 5:24 pm
by Sudeep

I'm trying to create a server code to call Google API (DistanceMatrix Service). But I'm getting an error:
"google is not defined ( @ 6 : 18 ) - var service = new google.maps.DistanceMatrixService();"

For a browser page, I would code window.onload or code a script to load https://maps.googleapis.com/maps/api/...

... and code the call to google API within "initialize" para. But on server side what do i code to resolve above problem?


Problem with calling google API from server script: "...google is not defined..."

Posted: Sat Jun 27, 2015 12:07 pm
by Serhii Kulibaba

Hello Sudeep,

How did you add this code to the server code? You can add JS code as library (https://devcenter.appery.io/documenta...)

Note: Server code doesn't have window object.


Problem with calling google API from server script: "...google is not defined..."

Posted: Sat Jun 27, 2015 2:17 pm
by Sudeep

Hi,
I'm not seeing how adding the JS code in Library would help.
I created a new library and wrote two JS functions there: initialize() & callback().

initialize() contains the call to google API among few other lines:
"var service = new google.maps.DistanceMatrixService();"

I created a new server script and just have one JS line in it:
initialize();

Here's the error trace log:
27.6.2015, 7:45:53 PM: Script gpsdist: ReferenceError: google is not defined ( @ 14 : 20 ) - var service = new google.maps.DistanceMatrixService();


Problem with calling google API from server script: "...google is not defined..."

Posted: Sat Jun 27, 2015 8:38 pm
by Illya Stepanov

Hi Sudeep -

Could you please clarify, have you added dependencies for this server script?


Problem with calling google API from server script: "...google is not defined..."

Posted: Sun Jun 28, 2015 12:53 am
by Sudeep

Hi,

Yes, I've included my newly added library to this server script wthin the 'dependencies' tab.

Regards,
Sudeep


Problem with calling google API from server script: "...google is not defined..."

Posted: Wed Jul 01, 2015 7:08 pm
by Serhii Kulibaba

Sudeep, Sorry, but this JS code doesn't look like server code (has window, document, etc.) so it is impossible to use in Appery.io server code.


Problem with calling google API from server script: "...google is not defined..."

Posted: Wed Jul 01, 2015 7:36 pm
by Sudeep

I'm sorry but there is no document/window in the JS code that I've coded as a library (not sure where you see it).

The JS code has this among other lines of code:
"var service = new google.maps.DistanceMatrixService();"

I created a new server script and just have one JS line in it:
initialize();
I've checked above created library within 'dependancies'.

Here's the error trace log from 4 days ago:
27.6.2015, 7:45:53 PM: Script gpsdist: ReferenceError: google is not defined ( @ 14 : 20 ) - var service = new google.maps.DistanceMatrixService();

Basically, I'm unable to call google service (as given above) from server code. If you've any example I'll be very curious to see it.


Problem with calling google API from server script: "...google is not defined..."

Posted: Fri Jul 03, 2015 7:19 pm
by Serhii Kulibaba

In this google library is not google variable. It is the cause of your issue.
And this library has window object: http://prntscr.com/7ogggi


Problem with calling google API from server script: "...google is not defined..."

Posted: Thu Dec 17, 2015 12:19 am
by Tim Inglis7933909

I have a very similar problem.

I would like to call the google distance martix JS api from the server code. I will take the data that is returned, do some data manipulation on it and feed the results back to the app.

The question is:

What do I have to do to use this google JavaScript api in the server code?

If i need to add a library, what library do I need to add? Where would I find such a library? Google's documentation seems to be for programming in an html environment, so it is not very helpful. It talks about typing in some code to load the library dynamically, but it seems that would need the JS source to load into APPERY.io.

any help you can offer would be greatly appreciated.

I would recommend a tutorial on how to make calls to REST apis from the server code in JS.

The goal here is to have the server do all of the calling of API's so the client only has to deal with a single API call - to the server. Also, If i want to maintain a database and automatically update it every (however long), then the server code should be able to call an API do the update, and have the information available in the database when the client comes calling.

Thanks

T


Problem with calling google API from server script: "...google is not defined..."

Posted: Thu Dec 17, 2015 7:12 pm
by Serhii Kulibaba