Google Geocoder

Wrapping google's geocoder for .Net

Since I starting out into the big world of HTML markup with netscape composer, back in the days when chicken really tasted like chicken and michel jackson was black, I've been pretty happy with the set of input controls that HTML 4 gave me.

Those native textareas, checkboxes, radio buttons and so on handle almost all the basice types of data I ever want to collect from a user with the with glaring exception of a date & time and, more recently, chunks of HTML markup, but fortunatly both of these cases have been more than addiquatly catered for by the numerouse WYSIWYG editing and date picking DHTML wigets that are available.

The advent of Web 2.0 paradigm, the proliferation of location based services and geographical tools like multimap and google's public mapping API has brought another basic type of information onto the presentation layer. Nameley a geographical position. A few years ago we might have been happy with a postal code or street name, now we want a blob on a map.

So it's time for another DHTML wiget. Like all good ideas now you can tell it's a good idea because google's already done it, We'r just going to wrap a little bit up and give it a name.

GoogleGeocoder.dll (Download)

Including the control on a page

<%@ Register Assembly="GoogleGeocoder" Namespace="ZapTheDingbat.GoogleGeocoder" TagPrefix="ztd" %>

...

<ztd:UserGeocoder ID="UserGeocoder1" runat="server" Height="200" Width="240" GoogleMapsApiKey="ABQIAAAAasXCzNlfivBEH..." />

Passing an Address to the control to Geocode

protected void btnFind_Click(object sender, EventArgs e)
{
    UserGeocoder1.Address = txtGeocode.Text;
}

Getting latitude & longitude values back from the control

protected void btnGetPosition_Click(object sender, EventArgs e) {
    lblLatLong.Text = String.Format("({0}, {1})",
    UserGeocoder1.Latitude,
    UserGeocoder1.Longitude
    );
}

Try it

Type the name of a place into the textbox and click find.

Drag the marker around to ajust the location

Click "Get Position" to show the lat/long returned by the control.


Result: ...