It’s becoming more and more popular for sites to tell you where you are. And, aside from being a neat thing to do, it is very useful in honing in onto what your users will find relevant even before the page is loaded. One method of retrieving the browser’s location is through using GeoMapLookUp.Net, however, there are many services out there. Drop down for a list of other location lookup methods.
In a previous post I’ve already described how to get the IP address of a browser using ServerVariables. We’ll use this method here. We’ll also be using a method provided by geomaplookup.net. You can view what this method returns by simply going to http://geomaplookup.net/index.php. Will be using the same url to download an kml file with the addition of ‘?kml=true&ip=
XmlDocument doc = new XmlDocument();
WebClient myclient = new WebClient();
string str = myclient.DownloadString(“http://geomaplookup.net/index.php?
kml=true&ip=” + GetIP());
The bulk of the code downloads a kml file from geomaplookup api and loads into into a xml document. The string to call is ‘http://geomaplookup.net/index.php?kml=true&ip=’ with the IP address at the end of the url. You can see what you get as the result by going to that url and inputing any old IP address. You can get yours from WhatIsMyIPAddress.com.
And that’s pretty much it.
Here’s some references for other methods of retrieving the physical location from IP Address.
Tags: .net, c#, ip, xml