public void BasicTest() { // downtown New York City StaticMapRequest request = new StaticMapRequest(new AddressLocation("Brooklyn Bridge,New York,NY"), 14, new ImageSize(512, 512)) { MapType = MapType.Roadmap, Markers = new List <Marker>() { new Marker() { Style = new MarkerStyle() { Color = "blue", Label = "S" }, Locations = new List <ILocation>() { new Location(40.702147, -74.015794) } }, new Marker() { Style = new MarkerStyle() { Color = "green", Label = "G" }, Locations = new List <ILocation>() { new Location(40.711614, -74.012318) } }, new Marker() { Style = new MarkerStyle() { Color = "red", Label = "C" }, Locations = new List <ILocation>() { new Location(40.718217, -73.998284) } } }, Sensor = false }; string generateStaticMapURL = staticMapGenerator.GenerateStaticMapURL(request); string expectedResult = @"http://maps.google.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=512x512&maptype=roadmap&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Clabel:C%7C40.718217,-73.998284&sensor=false"; Assert.AreEqual(expectedResult, generateStaticMapURL); }
public void TestMap(IEnumerable <Location> locations) { Console.WriteLine($"{nameof(TestMap)}:"); var markers = new List <Marker>() { new Marker() { Locations = locations.Cast <ILocationString>().ToList(), Style = new MarkerStyle() { Color = "red", } } }; var request = new StaticMapRequest(markers, new ImageSize(512, 512)) { ApiKey = ApiKey, }; var engine = new StaticMapsEngine() { }; Console.Write("\tGenerating Map URL ..."); try { var url = engine.GenerateStaticMapURL(request); Console.Write(url); } catch (Exception ex) { Console.Write($"\t{ex.GetType()} {ex.Message}"); } Console.WriteLine(); }
static void Main(string[] args) { // Driving directions var drivingDirectionRequest = new DirectionsRequest { Origin = "NYC, 5th and 39", Destination = "Philladephia, Chesnut and Wallnut" }; DirectionsResponse drivingDirections = GoogleMaps.Directions.Query(drivingDirectionRequest); PrintDirections(drivingDirections); // Transit directions var transitDirectionRequest = new DirectionsRequest { Origin = "New York", Destination = "Queens", TravelMode = TravelMode.Transit, DepartureTime = DateTime.Now }; DirectionsResponse transitDirections = GoogleMaps.Directions.Query(transitDirectionRequest); PrintDirections(transitDirections); var dep_time = DateTime.Today .AddDays(1) .AddHours(13); var request = new DirectionsRequest { Origin = "T-centralen, Stockholm, Sverige", Destination = "Kungsträdgården, Stockholm, Sverige", TravelMode = TravelMode.Transit, DepartureTime = dep_time, Language = "sv" }; DirectionsResponse result = GoogleMaps.Directions.Query(request); PrintDirections(result); // Geocode var geocodeRequest = new GeocodingRequest { Address = "new york city", }; GeocodingResponse geocode = GoogleMaps.Geocode.Query(geocodeRequest); Console.WriteLine(geocode); // Static maps API - get static map of with the path of the directions request var staticMapGenerator = new StaticMapsEngine(); //Path from previous directions request IEnumerable <Step> steps = drivingDirections.Routes.First().Legs.First().Steps; // All start locations IList <ILocationString> path = steps.Select(step => step.StartLocation).ToList <ILocationString>(); // 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); // Async! (Elevation) var elevationRequest = new ElevationRequest { Locations = new[] { new Location(54, 78) }, }; var task = GoogleMaps.Elevation.QueryAsync(elevationRequest) .ContinueWith(t => Console.WriteLine("\n" + t.Result)); Console.Write("Asynchronous query sent, waiting for a reply.."); while (!task.IsCompleted) { Console.Write('.'); Thread.Sleep(1000); } Console.WriteLine("Finished! Press any key to exit..."); Console.ReadKey(); }
static void Main(string[] args) { // Driving directions //var drivingDirectionRequest = new DirectionsRequest //{ // Origin = "NYC, 5th and 39", // Destination = "Philladephia, Chesnut and Wallnut" //}; var drivingDirectionRequest = new DirectionsRequest { TravelMode = TravelMode.Walking, Origin = "Ha-Va'ad ha-Le'umi 21, JERUSALEM, ISRAEL", //Destination = "kfar ivri ,10, Jerusalem,israel" Destination = "31.8414894,35.2471631" }; DirectionsResponse drivingDirections = GoogleMaps.Directions.Query(drivingDirectionRequest); Leg leg = PrintDirections(drivingDirections); Console.WriteLine("**********"); Console.WriteLine(leg.Distance.Text); Console.WriteLine(leg.Duration.Text); Console.WriteLine("*****************"); drivingDirectionRequest.TravelMode = TravelMode.Driving; DirectionsResponse drivingDirections2 = GoogleMaps.Directions.Query(drivingDirectionRequest); Leg leg2 = PrintDirections(drivingDirections2); Console.WriteLine("**********"); Console.WriteLine(leg2.Distance.Text); Console.WriteLine(leg2.Duration.Text); Console.WriteLine("*****************"); Console.ReadKey(); // Transit directions var transitDirectionRequest = new DirectionsRequest { Origin = "New York", Destination = "Queens", TravelMode = TravelMode.Transit, DepartureTime = DateTime.Now }; DirectionsResponse transitDirections = GoogleMaps.Directions.Query(transitDirectionRequest); PrintDirections(transitDirections); var dep_time = DateTime.Today .AddDays(1) .AddHours(13); var request = new DirectionsRequest { Origin = "T-centralen, Stockholm, Sverige", Destination = "Kungsträdgården, Stockholm, Sverige", TravelMode = TravelMode.Transit, DepartureTime = dep_time, Language = "sv" }; DirectionsResponse result = GoogleMaps.Directions.Query(request); PrintDirections(result); // Geocode //https://maps.googleapis.com/maps/api/geocode/json?address=Parque+Marechal+Mascarenhas+de+Morais&components=locality:Porto%20Aelgre|administrative_area:RS|country:BR var geocodeRequest = new GeocodingRequest { Address = "Parque Marechal Mascarenhas de Morais", Components = new GeocodingComponents() { Locality = "Porto Alegre", AdministrativeArea = "RS", Country = "BR" } }; GeocodingResponse geocode = GoogleMaps.Geocode.Query(geocodeRequest); Console.WriteLine(geocode); // Static maps API - get static map of with the path of the directions request var staticMapGenerator = new StaticMapsEngine(); //Path from previous directions request IEnumerable <Step> steps = drivingDirections.Routes.First().Legs.First().Steps; // All start locations IList <ILocationString> path = steps.Select(step => step.StartLocation).ToList <ILocationString>(); // 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 } }, ApiKey = string.Empty //Pass the API Key here. if it is passed as non empty value, then it will be appended in request URL }); Console.WriteLine("Map with path: " + url); // Async! (Elevation) var elevationRequest = new ElevationRequest { Locations = new[] { new Location(54, 78) }, }; var task = GoogleMaps.Elevation.QueryAsync(elevationRequest) .ContinueWith(t => Console.WriteLine("\n" + t.Result)); Console.Write("Asynchronous query sent, waiting for a reply.."); while (!task.IsCompleted) { Console.Write('.'); Thread.Sleep(1000); } Console.WriteLine("Finished! Press any key to exit..."); Console.ReadKey(); }
static void Main(string[] args) { //Static class use (Directions) 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) 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)"); Console.ReadKey(); }