I am using Node.js and MongoDB.
Let say I have predefined few cities (e.g. Seattle, Miami, New York) with Lat & Lon. and there is a user click to my website and I know his IP address, and find out the lat & lon. Then I want to know which city that I’ve defined is the closest to the user.
I know I can do it using Mongo’s geospatial feature. but it would be quite ‘expensive’ to use DB to calculate that for every web request.
Is there a Node.js NPM package that can do the geo feature as I described above?
If you already have the user’s location and the location of each city, it should be quite fast to compute the distance to the nearest. Check out this site: http://www.movable-type.co.uk/scripts/latlong.html
I have used the first algorithm a few times.
You might want to add some exception handling here 🙂