How to find the geoip location for all users in No

2020-02-11 13:57发布

问题:

I have a requirement where i have to find the geoip location of the users. I have used the code where i store the address of the user in database and then display the geoip location of that user.Now suppose the users changed his location to some other place.If the user now logs in from that region or country, how should i display the geoip of that user. The code that i use is:

geo.geocoder(geo.google, address, sensor,function(formattedAddress, latitude, longitude) {
             console.log("Formatted Address: " + formattedAddress);
             console.log("Latitude: " + latitude);
             console.log("Longitude: " + longitude);
             user.latitude = latitude;
             user.longitude = longitude;
             user.save(function(err) {
               if(err)
                 return userUpdateFailed();
               req.flash('info', 'Succesfully Upadated Changes');
               res.redirect('/userinfo');
             });
          });

Is there any alternative wherby i can be able to find the exact location of user.Please help

回答1:

Node-GeoIP could be a solution but keep in mind that ip-based geolocalization isn't always truthful.