I need to calculate the distance between two users, captured via Geolocation API.开发者_运维技巧 I have found the script, written in vanilla JS, that takes the Lat/Long pairs of both users and returns the distance between them:
var distance = distVincenty(lat1, lon1, lat2, lon2);
Please scroll to the bottom of the page for the script source: http://www.movable-type.co.uk/scripts/latlong-vincenty.html
I have tried using require('./lib/vincenty');
, however each time I call distVincenty()
it returns distVincenty is not defined
.
So how do I include/require vincenty.js
into Express bunch?
Have a read of "understanding Node.js' require".
What's happening is that just because you've required the file it doesn't mean that you get all of the functions in it. What you get is the functions the file adds to the special exports
object on the return value of the require call.
精彩评论