Skip to content
Maxim Novak edited this page Apr 22, 2017 · 6 revisions

This library wraps Google maps API.

You can easily query Google maps for Geocoding, Directions, Elevation, and 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)");

Setting the ApiKey

Set the SigningKey as part of the request - https://github.com/maximn/google-maps/blob/99cf8593eb351104d71697f6d817d738a5177f6b/GoogleMapsApi.Test/IntegrationTests/GeocodingTests.cs#L52

(In tests, you can set it in the app.config - https://github.com/maximn/google-maps/blob/master/GoogleMapsApi.Test/app.config)

Clone this wiki locally