Implement Geolocation using Scala and Lift


In this section , I will explain how to implement Geolocation using Scala and Lift . You can easily fetch user’s current location or near by location by his IP address .

1) You will need API key to be able to use . To get API key , just Go to IPInfoDB .
2) Get user’s IP address

 var ipAddress: String = ""
    S.containerRequest.map(r =>
      ipAdd = r.remoteAddress)

3)

val key:String = "Your API Key "

4)

var ipInfoDBURL = new URL("http://api.ipinfodb.com/v3/ip-city" + "/?key=" + key + "&ip=" + ipAddress + "&format=" + "json")
    val conn = ipInfoDBURL.openConnection

5)

conn.getInputStream

will provide you JSON with all details including latitude and longitude .

About Ayush Mishra

Ayush is the Sr. Software Consultant @ Knoldus Software LLP. In his 5 years of experience he has become developer with proven experience in architecting and developing web applications. Ayush has a Masters in Computer Application from U.P. Technical University, Ayush is a strong-willed and self-motivated professional who takes deep care in adhering to quality norms within projects. He is capable of managing challenging projects with remarkable deadline sensitivity without compromising code quality. .
This entry was posted in Agile, Java, Scala, Web. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s