Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement geoip in node.js and mongodb

I have seen few examples of using geoip in node.js such as https://github.com/kuno/GeoIP.git and https://github.com/wadey/node-geoip. However what i want is to display the map showing geoip for the particular loged in user.How can it be implemented.

like image 679
Dar Hamid Avatar asked Dec 14 '11 09:12

Dar Hamid


People also ask

How does MaxMind GeoIP work?

MaxMind periodically tests the accuracy of the data used in GeoIP2 products and services. Accuracy is calculated by checking known web user IP address and location pairs against the data within MaxMind's GeoIP2 web service as well as the GeoIP2 City and GeoLite2 City database offerings.

What are GeoIP databases?

What is an IP Geolocation Database? Geolocation IP Databases allow you to determine your website visitor's location. These databases of IP addresses contain the latitude and longitude of a particular IP address.


1 Answers

You can get a geolocation database (such as from http://www.maxmind.com) and store it in mongo. Each record contains an IP range (start/end) and the latitude/longitude associated with that IP range. IPs are represented as integers. You could create an index on the start field, and do a query on mongo to find the record with the largest value of start which is smaller than the IP of your client user, and look up the corresponding lat/lon.

As for plotting a map with this lat/lon, it's very easy to create a google map which is centered on a particular location: (View source at: http://code.google.com/apis/maps/documentation/javascript/v2/examples/map-simple.html)

There are a lot of different ways of storing/querying geolocation data, but this is just one possible approach using mongo that might work. Hope this helps.

like image 55
mpobrien Avatar answered Sep 22 '22 10:09

mpobrien