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

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.
- Crack open the beer and start a new vb.net project. Call it ‘GEOTest’. Take a well deserved drink.
- 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).
- Open the zip file into your project directory. Another sip. Add the files  ‘testCountryLookUp.aspx’, ‘testCountryLookUp.aspx.vb’ and ‘CountryLookup.vb’ to your project.
- Thirsty? More beer.
- 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.
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!
No related posts.