Previous     Next

Add GeoLocation to your site in less time than it takes to Drink a Beer

This is what a regular programmer looks like
Adding Geolocation to your website is so easy these days that I’ve decided that not only can we do it within 5 minutes, but to make it interesting I’ll bet that you’ve finished it before you can finish a beer.

OK? Got your beer? Lets go.

  1. Crack open the beer and start a new vb.net project. Call it ‘GEOTest’. Take a well deserved drink.
  2. Download the MaxMind Geo database and vb.net wrapper code from MaxMind (Complete list of supported languages - thanks again to MaxMind for doing all the work). Have some more beer while it downloads (thanks to my spankinglyfast ADSL2+ connection, no beer for me).
  3. Open the zip file into your project directory. Another sip. Add the files  ‘testCountryLookUp.aspx’, ‘testCountryLookUp.aspx.vb’ and ‘CountryLookup.vb’ to your project.
  4. Thirsty? More beer.
  5. Set the page ‘testCountryLookUp.aspx’ as your startup page, and then run the project. At this point it should run, but you may get a ‘Parser Error’ in the ‘testCountryLookUp.aspx’ file. To fix it, change:
    Inherits="testCountryLookUp"
    to
    Inherits="GEOTest.testCountryLookUp"
    in the  ‘testCountryLookUp.aspx’ file.
  6. Thats it! Done! You’ve probably still got plenty of beer left, so lets make some of our own code to get the country from IP Address.


Function CountryFromIP(ByVal Address As String) As String
   Dim oCountryLookup As CountryLookup = New CountryLookup(Server.MapPath("data/GeoIP.dat"))

   CountryFromIP = oCountryLookup.LookupCountryName(Address)
End Function

To call it, just use:
CountryName = CountryFromIP(Request.UserHostAddress)
Doesn’t work? Maybe too much beer…Passing your UserHostAddress won’t work from your local machine. To test, grab your IP address from somewhere like whatismyipaddress.com.

Still doesn’t work? Definitely time for another beer…


This post brought to you by WeGotDomain.com - Over 10,000 Aged domains for sale!

Related posts:

  1. Add Google Maps to your .Net site in 10 minutes


« « Remove HTML tags and Javascript from pages
Create a Website Comparison Widget using GoogleTrends » »

If you liked this, then subscribe to my RSS feed

Leave a reply