简体   繁体   中英

is it possible to use the google.maps api library on the node.js server side?

I am working on google map application which uses the google map version3 api, in particular the utility methods in google.maps.geometry.encoding, such as decodePath, encodePath, computeDistanceBetween, interpolate, in order to compute where the places

In the 1st version of web app, much of application logic is on the web broswer, and now I want to move some logic to the node.js based server. however, since the application depends on google api, I wonder is there a way that I can still use google map api on the node.js server

thanks in advance

You could use a module like node-googlemaps https://github.com/moshen/node-googlemaps that has already wrapped the API for you. Or, you could use any node module that will help you make API requests:

Mikeal's Request : https://github.com/mikeal/request

Restler : https://github.com/danwrong/restler

Although, I'm not sure about the utility methods specifically.

I did not find the way how to load and use geometry library from google maps in node.js But I found a small npm module geolib which can do some of calculations. I've compared results from the module and from google maps geometry library and they match. I hope you'll find it useful.

FOLLOW THESE STEP BY STEP INSTRUCTIONS

  1. Run this command in terminal npm install @google/maps --save

  2. Copy Paste this code

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

For Further Readings https://github.com/googlemaps/google-maps-services-js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM