Skip to content
maximnovak edited this page May 5, 2012 · 6 revisions

This library wraps Google maps API.

You can easily query Google maps for Geocoding, Directions, Elevation, and in the future also Places.

NEW! Now you can easily show the results on a Static Google Map!

This Library is well documented and easy to use.

Code sample -

//Static class use (Directions) (Can be made from static/instance class)
DirectionsRequest directionsRequest = new DirectionsRequest()
{
		Origin = "NYC, 5th and 39",
		Destination = "Philladephia, Chesnut and Wallnut",
};

DirectionsResponse directions = MapsAPI.GetDirections(directionsRequest);

Console.WriteLine(directions);


//Instance class use (Geocode)  (Can be made from static/instance class)
GeocodingRequest geocodeRequest = new GeocodingRequest()
{
		Address = "new york city",
};

GeocodingEngine geocodingEngine = new GeocodingEngine();

GeocodingResponse geocode = geocodingEngine.GetGeocode(geocodeRequest);

Console.WriteLine(geocode);


// Static maps API - get static map of with the path of the directions request
StaticMapsEngine staticMapGenerator = new StaticMapsEngine();

//Path from previos directions request
IEnumerable<Step> steps = directions.Routes.First().Legs.First().Steps;
// All start locations
IList<ILocation> path = steps.Select(step => step.StartLocation).ToList<ILocation>();
// also the end location of the last step
path.Add(steps.Last().EndLocation);

string url = staticMapGenerator.GenerateStaticMapURL(new StaticMapRequest(new Location(40.38742, -74.55366), 9, new ImageSize(800, 400))
{
		Pathes = new List<Path>(){ new Path()
		{
				Style = new PathStyle()
				{
						Color = "red"
				},
				Locations = path
		}}


});

Console.WriteLine("Map with path: " + url);



//Instance class - Async! (Elevation)
ElevationRequest elevationRequest = new ElevationRequest()
{
		Locations = new Location[] { new Location(54, 78) },
};

ElevationEngine elevationEngine = new ElevationEngine();

elevationEngine.BeginGetElevation(elevationRequest,
										ar =>
										{
												ElevationResponse elevation = elevationEngine.EndGetElevation(ar);
												Console.WriteLine(elevation);
										},
										null);

Console.WriteLine("Finised! (But wait .. async elevation request should get response soon)");
Clone this wiki locally