I am working on a project that requires a gsm Module (sim900d) send two location coordinates (current location and destination) to a server and get the direction using google maps api in response.
I started out with JavaScript and php and latter realized that JavaScript is client side and php is server side and that I can't send a javascript variable to php. I now know that I'll have to use node.js for my project. I have a little experience with JavaScript but my node.js knowledge is limited to hello world web server.
I've tried running directions-test.js for node-googlemaps unsuccessfully.
The exact code was giving an error "cannot find module '../lib/googlemaps'" so i replaced the "'../lib/googlemaps'" with 'googlemaps', it runs fine but all i get is sqrt(OK) >> 2 honored (0.896s).
I know I have to insert my google maps api key somewhere but can't figure out where and the syntax. And can someone please tell me where the directions object would be?
Edit: I am an electrical engineering student, please be elaborate in your answers. My project is EE related, I cannot learn everything and write code from scratch (due to time constraints) so related example codes would be much appreciated.
Edit 2: I have just realized that directions-test.js for node-googlemaps is not an example code, rather its Test code using vows. Vows as its website defines it is was built from the ground up to test asynchronous code. It executes your tests in parallel when it makes sense, and sequentially when there are dependencies.
var gm = require('googlemaps');
var util = require('util');
gm.config('key', '<insert your api key here>');
gm.directions('31.470656,74.412929', '31.470789,74.408619' ,
function(err, data){util.puts(JSON.stringify(data));});
This is how you get directions between two locations.
Related
I have Node app with mongo db that works perfectly in localhost, but as I deploy it to Google App Engine one particular function of the app stops working. This function uses .map to get information from mongo db; fetching a value into javascript object based on the mongo generated _id field.
Questions are:
Is there a reason (perhaps environment) why this would not work in Google App Engine?
Is there a good alternative to .map? .forEach is the best?
Any other pointers where I could start troubleshooting from with something working in localhost and not deployed to GAE?
1 and 3 - Can you explain how did you set your app? Can you check the logs and see what's going wrong? You can check this community tutorial on how to connect Node.js to Mongo db. My guess is that you missed installing some libraries that are on the localhost server but not once you deploy, but without further clarification I cannot answer. I will update if more info is provided.
2- .forEach execute a function for each element of one array but .map creates an array with the result of executing a function for each element, the difference is very subtle . In general, .forEach is better if you are not going to change data in the original array (such as printing the value) and .map is better if you want to change it (converting to float for example).
I'm just starting to use nodejs. I've done some basic learning course but I miss any basic example to start becaue I'm having problems to deploy an scenario for the first time.
The scenario I need to cover is:
I just need to write and read data from an Access.MDB file.
I have a basic example that works if I execute the js with the sentence \node appnodemdb.js from the command line.
But I need to execute it from another js in a web.
So I'd appreciate a lot if anyone could send me an example about execute it from an other js without the command line.
Thanks a lot for your help!
You can't call directly some NodeJS code with the browser. To achieve what you want, the simplest way to do is:
Create an HTTP server with a URL to will launch your write/write action and return some value (with Express for example).
This URL will be called by your JS in the browser (using XHR/Ajax) and process the data returned.
They are tons of alternative to do this, but since you tell us that you are beginner, I suggest this approach.
I have an existing Javascript/HTML Application. I wanted to use power of R Programming's scientific computing and graphics.
My aim is to,
Send some data from Javascript app.
Call predefined R functions with the data input.
Get the output get the output in the form of both text and graphics.
Display it in the HTML page.
How to achieve this,
Should I run R continuously, use something like web sockets and connect to R? If doing How to pass R scripts to execute and get the output pack?
There is Rserve. There are some nodeJS implementation for Rserve. But problem with this is, each line of code should be passed through the evaluate commands. Even though if I do so, how to handle the graph output?
I explored a bit of openCPU. If using openCPU R package, R should be continuously Running with opencpu library and each we start R and openCPU, it starts with different port number. And if i close the R session, opencpu server also terminates.
If I install standalone opencpu server in my machine, how to use R with this? I've installed openCPU standalone server and a kind of stuck after that.
How should I proceed, What should I do to accomplish my task. I'm like a kind of don't know which direction to go. Please throw some light on this. I'm sure most people would need this.
I have worked with shiny, but in this case, I can not make use of it. Need to connect R from external Web Application.
FastRWeb sounds like it would be perfect for your needs. From the documentation:
FastRWeb is an infrastructure that allows any webserver to use R
scripts for generating content on the fly, such as web pages or
graphics. URLs are mapped to scripts and can have optional arguments
that are passed to the R function run from the script. For example
http://my.server/cgi-bin/R/foo.png?n=100 would cause FastRWeb to look
up a script foo.png.R, source it and call run(n="100"). So for example
the script could be as simple as
run <- function(n=10, ...) {
p <- WebPlot(800, 600)
n <- as.integer(n)
plot(rnorm(n), rnorm(n), col=2, pch=19)
p
}
This can potentially then be called using JavaScript to dynamically load images and display them.
You might also like to think about shiny, though that's more of a complete solution.
You can call R from javascript efficiently using Rserve package. There is javascript implementation of Rserve client available rserve-js.
Additionally you may find it interesting the httupv implementation of R as a service described in this Suggestions needed for building R server REST API's that I can call from external app?.
I've been comparing several SDKs in order to add some location-based AR in one of my Android Apps. So far I've really liked the overall simplicity of Wikitude, however there are things like them asking you to put some of the logic of the AR part in javascript files that confuse me.
What are you supposed to do with the javascript, what role does it serves in the overall flow between an Android Activity and the AR?
Also, as a side question, what sense is there to make out of this line in the Android documentation of Wikitude:
architectView.callJavascript(newData('" + poiDataAsJson +")')
at http://developer.wikitude.com/documentation/android. I assume there is a typo or mistake somewhere as newData is not defined anywhere in the Android code.
Thank you!
In order to enable cross platform augmented reality experiences, web technologies were chosen. The application flow is usually that the ArchtiectView is initialised and displayed by the native application. An AR experience is loaded which consists of an html file that executes javascript functions to create the objects in AR.
callJavascript method is used natively to communicate with the loaded AR exprience. It executes the passed javascript in the context of the loaded AR experience. Therefore it can be used to pass POI data as json to a function declared in the Javascript part.
There is an error in the posted java code
architectView.callJavascript(newData('" + poiDataAsJson +")')
should include 2 more double quotes
architectView.callJavascript("newData('" + poiDataAsJson +")'")
This executes the function newData declared globally in javascript and passes 1 parameter, the json encoded poi data.
Disclaimer: I work for Wikitude
I'm trying to run envjs and Rhino in a java application to render SVGs with D3.js.
So far, I can evaluate smaller functions using Rhino but when it comes to setting up envjs, the problems begin. The most important one is that the only tutorial for envjs talks about a file called env.rhino.js. But I have no idea where to find it.
Can anybody help me out?
(Yes, google shows some results but they are not officially belonging to Rhino or envjs)
I know this answer is very late. But I want to do the same and had the same problems - maybe this will help the next one. It took a while to figure out which one of the hundrets of github forks on env-js will do the job. I found out that this combination will work for a simple test:
git clone https://github.com/thatcher/envjs-site.git
#note the different fork!
wget https://raw.github.com/thatcher/env-js/master/src/dom/sizzle.js
wget http://d3js.org/d3.v3.min.js
java -jar dist/env-js-1.1.jar
load("lib/env.rhino.js");
load("sizzle.js");
load("d3.v3.min.js");
d3.select("body").append("svg").selectAll("line").data([1,2]).enter().append("line").attr("x1", function(d){return d;});
document.innerHTML;
<html><head/><body><line/><line/><svg xmlns="http://www.w3.org/2000/svg"><line x1="1"/><line x1="2"/></svg></body><line/><line/></html>
j
First, download env.rhino.js.
Then, use this Java code to start a Rhino instance and load Env.js:
import org.mozilla.javascript.Context;
import org.mozilla.javascript.tools.shell.Global;
import org.mozilla.javascript.tools.shell.Main;
Context cx = Context.enter();
Global scope = new Global(cx);
cx.setOptimizationLevel(-1);
cx.setLanguageVersion(Context.VERSION_1_5);
Now you can load and run a JavaScript file (using its absolute file-system path)
Main.processFile(cx, scope, ABSOLUTE_PATH_TO_SOME_JAVASCRIPT_FILE);
And/or evaluate JavaScript code and get its String result
(String)cx.evaluateString(scope, "alert('Its WORKING!')", "js", 1, null);
I did attempt this but couldn't go very far. I also wanted to generate SVGs on server side, with requests being initiated from java(Glassfish in my case). The only way you can do this is with jsdom & Node.js. I am able to do this successfully. Sadly, other than Node.js + jsdom, there seems no other way to do this.
Once you get it working, there are bigger problems lurking if you try to heavily load Node.js with SVG generation requests.