示例#1
0
		public void ImageSize()
		{
			var request = new StaticMapRequest(new Location(0, 0), 1, new ImageSize(400, 50));
			string expectedResult = "http://maps.google.com/maps/api/staticmap" +
									"?center=0%2C0&zoom=1&size=400x50&sensor=false";

			string generateStaticMapURL = new StaticMapsEngine().GenerateStaticMapURL(request);

			Assert.AreEqual(expectedResult, generateStaticMapURL);
		}
示例#2
0
		public void ZoomLevels()
		{
			var request = new StaticMapRequest(new Location(40.714728, -73.998672), 12, new ImageSize(400, 400));
			string expectedResult = "http://maps.google.com/maps/api/staticmap" +
									"?center=40.714728%2C-73.998672&zoom=12&size=400x400&sensor=false";

			string generateStaticMapURL = new StaticMapsEngine().GenerateStaticMapURL(request);

			Assert.AreEqual(expectedResult, generateStaticMapURL);
		}
示例#3
0
		public void AddressTest()
		{
			var request = new StaticMapRequest(new AddressLocation("Berkeley,CA"), 14, new ImageSize(400, 400));
			string expectedResult = "http://maps.google.com/maps/api/staticmap" +
									"?center=Berkeley%2CCA&zoom=14&size=400x400&sensor=false";

			string generateStaticMapURL = new StaticMapsEngine().GenerateStaticMapURL(request);

			Assert.AreEqual(expectedResult, generateStaticMapURL);
		}
示例#4
0
		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<ILocationString> { new Location(40.702147, -74.015794) }
									},
								new Marker
									{
										Style = new MarkerStyle { Color = "green", Label = "G" },
										Locations = new List<ILocationString> { new Location(40.711614, -74.012318) }
									},
								new Marker
									{
										Style = new MarkerStyle { Color = "red", Label = "C" },
										Locations = new List<ILocationString> { new Location(40.718217, -73.998284) }
									}
							},
					Sensor = false
				};
			string expectedResult = "http://maps.google.com/maps/api/staticmap" +
									"?center=Brooklyn%20Bridge%2CNew%20York%2CNY&zoom=14&size=512x512&maptype=roadmap" +
									"&markers=color%3Ablue%7Clabel%3AS%7C40.702147%2C-74.015794&markers=color%3Agreen%7Clabel%3AG%7C40.711614%2C-74.012318" +
									"&markers=color%3Ared%7Clabel%3AC%7C40.718217%2C-73.998284&sensor=false";

			string generateStaticMapURL = new StaticMapsEngine().GenerateStaticMapURL(request);

			Assert.AreEqual(expectedResult, generateStaticMapURL);
		}
示例#5
0
        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
            //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
                    }}
            });

            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();
        }
示例#6
0
		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);

			// 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();
		}
示例#7
0
		public void MapTypes()
		{
			var request = new StaticMapRequest(new Location(40.714728, -73.998672), 12, new ImageSize(400, 400));
			request.MapType = MapType.Terrain;
			string expectedResult = @"http://maps.google.com/maps/api/staticmap" +
									@"?center=40.714728%2C-73.998672&zoom=12&size=400x400&maptype=terrain&sensor=false";

			string actualResult = new StaticMapsEngine().GenerateStaticMapURL(request);

			Assert.AreEqual(expectedResult, actualResult);
		}