Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
150 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...