Project Description

.NET wrapper for the Google Maps API services, like Directions and Geocoding. This wrapper help you to find any address, postal code, geolocalization, and also to get directions between locations.

See the complete reference below:
http://code.google.com/intl/en-US/apis/maps/documentation/directions/
http://code.google.com/intl/en-US/apis/maps/documentation/geocoding/

Google is awesome! This wrapper is only an easy way to help you on your .NET Applications.

Enjoy it...!

 

I would like to get your feedback!

I really apreciate it! Please, send an e-mail to evandro.venancio@gmail.com or send a tweet to @evenancio.

 

* THANK YOU !!! *


Sample

To use this, adds GoogleAPI.Maps reference and System.ServiceModel in your application.

For use Directions API, follow this example:

using System.Linq;
using GoogleAPI.Maps.Services;
 
namespace GoogleAPI.Maps.Tests {
    class Class1 {
        public void GetRoutes() {
            var directionsAPI = new Directions();
            string origin = "09571-300";
            string destination = "09812-000";
 
            var actual = directionsAPI.GetRoutes(origin, destination);
            string res = string.Empty;
 
            actual.Routes.FirstOrDefault().
                Legs.FirstOrDefault().
                Steps.ToList().
                    ForEach(x => res += x.HtmlInstructions + "<BR />");
        }
    }
}

For use Geocoding API, follow this example:

using System;
using System.Globalization;
using System.Linq;
using GoogleAPI.Maps.Services;
 
namespace GoogleAPI.Maps.Tests {
    class Class1 {
        public void GetAddressByPostalCodeTest() {
            string address = GetAddress("04055-110");
        }
 
        public void GetPostalCodeByAddressTest() {
            string postalCode = GetPostalCode(
                "Av Capitao Casa - Sao Bernardo do Campo - SP - Brazil");
        }
 
        private string GetAddress(string postalCode) {
            var target = new Geocoding();
            var addressLocation = target.GetByAddress(postalCode).
                Results[0].Geometry.Location;
            var addressInformation = target.GetByCardinalDirection(
                String.Format("{0},{1}",
                    addressLocation.Latitude.
                        ToString(new CultureInfo("en-US")),
                    addressLocation.Longitude.
                        ToString(new CultureInfo("en-US"))));
            var address = addressInformation.Results[0].FormattedAddress;
            return address;
        }
 
        private string GetPostalCode(string address) {
            var target = new Geocoding();
            var addressLocation = target.GetByAddress(address).
                Results[0].Geometry.Location;
            var addressInformation = target.GetByCardinalDirection(
                String.Format("{0},{1}",
                    addressLocation.Latitude.
                        ToString(new CultureInfo("en-US")),
                    addressLocation.Longitude.
                        ToString(new CultureInfo("en-US"))));
            return addressInformation.Results[0].
                AddressComponents.Where(s => 
                    s.GeoTypes.Contains("postal_code")).
                        FirstOrDefault().LongName;
        }
    }
}

Don’t forget to adds this content in your config of application that’s hosts this wrapper:

<system.serviceModel>
    <client>      
      <endpoint address="http://maps.google.com/maps/api/geocode/"
     binding="webHttpBinding"
     bindingConfiguration="webBinding"
     behaviorConfiguration="geocodingBehavior"
     contract="GoogleAPI.Maps.Services.IGeocoding"
     name="GoogleGeocondigREST" />
 
      <endpoint address="http://maps.google.com.br/maps/api/directions/"
     binding="webHttpBinding"
     bindingConfiguration="webBinding"
     behaviorConfiguration="geocodingBehavior"
     contract="GoogleAPI.Maps.Services.IDirections"
     name="GoogleDirectionsREST" />
    </client>
 
    <bindings>
      <webHttpBinding>
        <binding name="webBinding">
          <security mode="None"></security>
        </binding>
      </webHttpBinding>    
    </bindings>
 
    <behaviors>
      <endpointBehaviors>
        <behavior name="geocodingBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
 
  </system.serviceModel>

Last edited Sep 23, 2011 at 7:40 PM by evenancio, version 2