This evening I ran across Tiny Geo Coder and decided the time was right to update BlogEngine.NET. I have seen several requests to add the ability to lookup the Geo information while in the BlogEngine.NET settings page:
Up till now no one has spent the time to allow this functionality and you had to go to an external resource to obtain the Latitude/Longitude information. (Hey, I just noticed Longtitude is misspelled on the page, doh) But with TinyGeo-coder it couldn’t be easier. Here’s how I did it…
A simple update to the ~/admin/pages/settings.aspx page to include the input field and the button:
<label for="txtGeoLookup">Lookup Geo Info</label> <asp:TextBox runat="server" ID="txtGeoLookup" Width="300" /> <asp:Button runat="server" ID="btnGeoLookup" Text="Lookup" onclick="btnGeoLookup_Click1" /><br /><br />
Next we need a function in the ~/admin/pages/settings.aspx.cs page that contains the necessary calls:
protected void btnGeoLookup_Click1(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtGeoLookup.Text))
return;
try
{
string urlAddress = "http://tinygeocoder.com/create-api.php?q=" + txtGeoLookup.Text;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(urlAddress);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(receiveStream, encode);
Char[] read = new Char[256];
int count = readStream.Read(read, 0, 256);
String str = new String(read, 0, count);
string[] geoInfo = str.Split(',');
txtGeocodingLatitude.Text = geoInfo[0];
if (str.Contains("ERROR"))
txtGeocodingLongitude.Text = string.Empty;
else
txtGeocodingLongitude.Text = geoInfo[1];
response.Close();
readStream.Close();
}
catch (Exception)
{ return; }
}
and that’s it… Here’s the results:
Nothing too difficult but it now populates your Latitude and Longitude information. If you want this for your blog then simply replace your settings.aspx files (back them up first!) with the ones in my attached zip file and you should be all set! And after you have populated this you can add my GeoURL Extension!
Useful? Let me know!




Kim Cameron's Identity Weblog
Mon, Nov 10, 2008
Technology