In this blog , I will explain how to obtain Geolocation in Play Scala application from IP address of user . You can easily fetch user’s current location or near by location by his IP address .
1) You will require API key to be able to use this feature. To get API key , just go to IPInfoDB .
2) Get user’s IP address
3) Provide the IPInfoDB’s API Key
4) Then obtain the user’s location from the following link
5) At last get the data from the Input Stream of connection
will provide you Geolocation in JSON format with all details including Latitude and Longitude.
Note :- Add following line in application.conf file
Otherwise Play application wont be able to fetch Public IP Address of User.
Reblogged this on Play!ng with Scala.
Better use the play WS instead of URL to avoid blocking
Thanks for your feedback. I will definitely take a look at it.