问题描述
我正在开发一个项目,需要一个gsm模块(sim900d)向服务器发送两个位置坐标(当前位置和目的地),并使用google maps api作为回应。
我从JavaScript和PHP开始,后者意识到JavaScript是客户端,php是服务器端,我无法发送JavaScript变量到php。我现在知道我必须为我的项目使用node.js。我对JavaScript有一点经验,但是我的node.js知识仅限于。
我试过运行失败。
确切的代码给出错误找不到模块 ../ lib / googlemaps',所以我用'googlemaps'取代了''../lib/googlemaps'',它运行良好,但我得到的是sqrt(OK)>> 2 honored(0.896s )。
我知道我必须在某处插入我的Google Maps API密钥,但无法弄清楚在哪里和语法。有人可以告诉我方向对象的位置吗?
编辑:我是一名电气工程专业的学生,请详细说明您的答案。我的项目与EE相关,我无法学习所有东西并从头开始编写代码(由于时间限制),所以相关的示例代码将非常感谢。
编辑2:我有刚刚意识到不是示例代码,而是其使用誓言的测试代码。 是从头建立起来测试异步代码的。它在有意义的时候并行地执行你的测试,并且当依赖时依次执行你的测试。
var gm = require('googlemaps');
var util = require('util');
gm.config('key','<在此处插入您的API密钥>');
gm.directions('31 .470656,74.412929','31 .470789,74.408619',
function(err,data){util.puts(JSON.stringify(data));});
这是您如何获取两个地点之间的路线。
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.
这篇关于使用node-googlemaps从Google地图获取方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!