我正在使用谷歌地图应用程序,它使用谷歌地图版本3 api,特别是google.maps.geometry.encoding中的实用程序方法,例如decodePath,encodePath,computeDistanceBetween,interpolate,以便计算地点的位置< / p>
在Web应用程序的第一个版本中,很多应用程序逻辑都在Web浏览器上,现在我想将一些逻辑移动到基于node.js的服务器上。但是,由于应用程序依赖于google api,我想知道有没有办法让我仍然可以在node.js服务器上使用google map api
提前致谢
答案 0 :(得分:9)
您可以使用已经为您包装API的 node-googlemaps https://github.com/moshen/node-googlemaps等模块。或者,您可以使用任何可以帮助您发出API请求的节点模块:
Mikeal的请求:https://github.com/mikeal/request
Restler :https://github.com/danwrong/restler
虽然,我不确定具体的实用方法。
答案 1 :(得分:1)
我没有找到如何从node.js中的谷歌地图加载和使用几何库的方法但是我找到了一个小的npm模块geolib,它可以进行一些计算。我比较了模块和谷歌地图几何图库的结果,它们相匹配。我希望你会发现它很有用。
答案 2 :(得分:0)
按照这些说明进行操作
在终端npm install @google/maps --save
复制粘贴此代码
var googleMapsClient = require('@google/maps').createClient({
key: xxxxxxxxxx
});
function getDirections (req, callback) {
googleMapsClient.directions({
origin: req.origin,
destination: req.destination,
mode: req.mode,
}, function(err, response) {
console.log(err);
console.log(response);
if (!err) {
callback(response);
};
});
};
var inputs = {
origin: "1600 Amphitheatre Parkway, Mountain View, CA",
destination: "1 Infinite Loop, Cupertino, CA 95014, USA",
mode: "driving",
};
getDirections(inputs, function(result){
console.log("Response: ", JSON.stringify(JSON.parse(JSON.stringify(result))))
});