Google Geocoder 1.1 (C#, .NET 3.5)
Version 1.1December 2008C#.NET 3.5open source
Download · ZIP · 76 KB
The ScipBe.Common.Geocoding namespace contains the GoogleGeoCoder class. This class uses the Google Maps Geocoding HTTP REST service to retrieve geographical data like the latitude and longitude of a given address.
Check out one of my articles where I describe the implementation of this GoogleGeoCoder class.
Class diagram:
C# examples:
GoogleGeoCoder geoCoder = new GoogleGeoCoder("A Google Maps API key");
IGeoData geoData = geoCoder.GetGeoData("Street City Country");
if (geoData.Status == GeoStatusCode.Success)
{
Console.WriteLine(geoData.Accuracy);
Console.WriteLine("{0}:{1}", geoData.Coordinate.Longitude, geoData.Coordinate.Latitude);
}
GoogleGeoCoder geoCoder = new GoogleGeoCoder("A Google Maps API key");
IGeoData geoData = geoCoder.GetGeoData("Street City Country");
if (geoData.Status == GeoStatusCode.Success)
{
Console.WriteLine(geoData.Accuracy);
Console.WriteLine("Address = {0}", geoData.Address);
Console.WriteLine("Thoroughfare = {0}", geoData.ThoroughfareName);
Console.WriteLine("Locality = {0}", geoData.DependentLocalityName);
Console.WriteLine("Administrative area = {0}", geoData.AdministrativeAreaName);
Console.WriteLine("Country = {0}", geoData.CountryNameCode);
Console.WriteLine("{0}:{1}", geoData.Coordinate.Longitude, geoData.Coordinate.Latitude);
}
GoogleGeoCoder geoCoder = new GoogleGeoCoder("A Google Maps API key");
geoCoder.GeoListCompleted += new GeoListCompletedEventHandler(geoCoder_GeoListCompleted);
geoCoder.GetGeoListAsync("Street City Country");
void geoCoder_GeoListCompleted(object sender, IEnumerable<IGeoData> geoList)
{
if ((geoList.Count() > 0) && (geoList.First().Status == GeoStatusCode.Success))
{
foreach (var geoData in geoList)
{
Console.WriteLine("Address = {0}", geoData.Address);
Console.WriteLine("Country = {0}", geoData.CountryNameCode);
Console.WriteLine("Coordinates = {0}:{1}", geoData.Coordinate.Longitude, geoData.Coordinate.Latitude);
}
}
}
Copyrights and distribution
- These components are open source (Mozilla Public License 1.1) and may be freely distributed.
- The author doesn't give a warranty for error free running of these components and he doesn't give any support.
- See source code and help file for more information about the classes, interfaces, properties, methods, events, ...
Download
Google Geocoder
Components with sources and help file (C#, .NET 3.5, Visual Studio 2008)
- Version
- 1.1
- Date
- File size
- 76 KB
- Author
- Stefan Cruysberghs