Sudeep
Posts: 0
Joined: Fri Jun 26, 2015 5:24 pm

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

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?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

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

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.

Sudeep
Posts: 0
Joined: Fri Jun 26, 2015 5:24 pm

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

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();

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

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

Hi Sudeep -

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

Sudeep
Posts: 0
Joined: Fri Jun 26, 2015 5:24 pm

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

Hi,

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

Regards,
Sudeep

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

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

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.

Sudeep
Posts: 0
Joined: Fri Jun 26, 2015 5:24 pm

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

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

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

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

Tim Inglis7933909
Posts: 0
Joined: Thu Dec 17, 2015 12:19 am

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

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

Return to “Issues”