private string GetMyPlaceId() { if (cachedMyPlaceId == null) { var request = new Entities.Places.Request.PlacesRequest() { ApiKey = ApiKey, Name = "My Place Bar & Restaurant", Location = new Location(-31.954453, 115.862717), RankBy = Entities.Places.Request.RankBy.Distance, }; var result = GoogleMaps.Places.Query(request); AssertInconclusive.NotExceedQuota(result); cachedMyPlaceId = result.Results.First().PlaceId; } return(cachedMyPlaceId); }
public void TestNearbySearchType() { var request = new PlacesNearByRequest { ApiKey = ApiKey, Radius = 10000, Location = new Location(40.6782552, -73.8671761), // New York Type = "airport", }; PlacesNearByResponse result = GoogleMaps.PlacesNearBy.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(Status.OK, result.Status); Assert.IsTrue(result.Results.Any()); Assert.IsTrue(result.Results.Any(t => t.Name.Contains("John F. Kennedy"))); }
public void ShouldReturnDurationInTrafficWhenDepartureTimeAndApiKeySpecified() { var request = new DistanceMatrixRequest { ApiKey = ApiKey, DepartureTime = new Time(), Origins = new[] { "49.64265,12.50088" }, Destinations = new[] { "53.64308,10.52726" }, }; var result = GoogleMaps.DistanceMatrix.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status, result.ErrorMessage); Assert.IsNotNull(result.Rows.First().Elements.First().DurationInTraffic); }
public void Directions_WithWayPoints() { var request = new DirectionsRequest { Origin = "NYC, USA", Destination = "Miami, USA", Waypoints = new string[] { "Philadelphia, USA" }, OptimizeWaypoints = true, ApiKey = ApiKey }; var result = GoogleMaps.Directions.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(DirectionsStatusCodes.OK, result.Status, result.ErrorMessage); Assert.AreEqual(156097, result.Routes.First().Legs.First().Steps.Sum(s => s.Distance.Value), 10 * 1000); StringAssert.Contains("Philadelphia", result.Routes.First().Legs.First().EndAddress); }
public void Directions_CanGetDurationWithTraffic() { var request = new DirectionsRequest { Origin = "285 Bedford Ave, Brooklyn, NY, USA", Destination = "185 Broadway Ave, Manhattan, NY, USA", DepartureTime = DateTime.Now.Date.AddDays(1).AddHours(8), ApiKey = ApiKey //Duration in traffic requires an API key }; var result = GoogleMaps.Directions.Query(request); AssertInconclusive.NotExceedQuota(result); //All legs have duration Assert.IsTrue(result.Routes.First().Legs.All(l => l.DurationInTraffic != null)); //Duration with traffic is usually longer but is not guaranteed Assert.AreNotEqual(result.Routes.First().Legs.Sum(s => s.Duration.Value.TotalSeconds), result.Routes.First().Legs.Sum(s => s.DurationInTraffic.Value.TotalSeconds)); }
public void Directions_VerifysubSteps() { var request = new DirectionsRequest { Origin = "75 9th Ave, New York, NY", Destination = "MetLife Stadium Dr East Rutherford, NJ 07073", TravelMode = TravelMode.Driving }; DirectionsResponse result = GoogleMaps.Directions.Query(request); AssertInconclusive.NotExceedQuota(result); var route = result.Routes.First(); var leg = route.Legs.First(); var step = leg.Steps.First(); Assert.NotNull(step); }
public void Directions_Correct_OverviewPath() { DirectionsRequest request = new DirectionsRequest(); request.Destination = "maleva 10, Ahtme, Kohtla-Järve, 31025 Ida-Viru County, Estonia"; request.Origin = "veski 2, Jõhvi Parish, 41532 Ida-Viru County, Estonia"; DirectionsResponse result = GoogleMaps.Directions.Query(request); AssertInconclusive.NotExceedQuota(result); OverviewPolyline overviewPath = result.Routes.First().OverviewPath; OverviewPolyline polyline = result.Routes.First().Legs.First().Steps.First().PolyLine; IEnumerable <Location> points = result.Routes.First().OverviewPath.Points; Assert.AreEqual(DirectionsStatusCodes.OK, result.Status, result.ErrorMessage); Assert.AreEqual(122, overviewPath.Points.Count(), 30); Assert.Greater(polyline.Points.Count(), 1); }
public async Task TestNearbySearchPaginationAsync() { var request = new PlacesRequest { ApiKey = ApiKey, Keyword = "pizza", Radius = 10000, Location = new Location(47.611162, -122.337644), //Seattle, Washington, USA }; PlacesResponse result = await GoogleMaps.Places.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(Status.OK, result.Status); //we should have more than one page of pizza results from the NearBy Search Assert.IsTrue(!String.IsNullOrEmpty(result.NextPage)); //a full page of results is always 20 Assert.IsTrue(result.Results.Count() == 20); var resultFromFirstPage = result.Results.FirstOrDefault(); //hold onto this //get the second page of results. Delay request by 2 seconds //Google API requires a short processing window to develop the second page. See Google API docs for more info on delay. Thread.Sleep(2000); request = new PlacesRequest { ApiKey = ApiKey, Keyword = "pizza", Radius = 10000, Location = new Location(47.611162, -122.337644), //Seattle, Washington, USA PageToken = result.NextPage }; result = await GoogleMaps.Places.QueryAsync(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(Status.OK, result.Status); //make sure the second page has some results Assert.IsTrue(result.Results != null && result.Results.Any()); //make sure the result from the first page isn't on the second page to confirm we actually got a second page with new results Assert.NotNull(resultFromFirstPage); Assert.IsFalse(result.Results.Any(t => t.PlaceId == resultFromFirstPage.PlaceId)); }
public void Directions_WithRegionSearch() { var dep_time = DateTime.Today .AddDays(1) .AddHours(13); var request = new DirectionsRequest { Origin = "Mt Albert", Destination = "Parnell", TravelMode = TravelMode.Transit, DepartureTime = dep_time, Region = "nz" }; DirectionsResponse result = GoogleMaps.Directions.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.IsNotEmpty(result.Routes); Assert.True(result.Status.Equals(DirectionsStatusCodes.OK)); }
public void TypeTest() { var request = new PlaceAutocompleteRequest { ApiKey = base.ApiKey, Input = "abb", Type = "geocode", Location = new Entities.Common.Location(53.4635332, -2.2419169), Radius = 30000 }; PlaceAutocompleteResponse result = GoogleMaps.PlaceAutocomplete.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(Status.OK, result.Status); foreach (var oneResult in result.Results) { Assert.IsNotNull(oneResult.Types, "result with no type classification"); Assert.IsTrue(new List <string>(oneResult.Types).Contains("geocode"), "non-geocode result"); } }
public void ShouldReturnValidValueWhenTwoOriginsSpecified() { var request = new DistanceMatrixRequest { Origins = new[] { "49.64265,12.50088", "49.17395,12.87028" }, Destinations = new[] { "53.64308,10.52726" } }; var result = GoogleMaps.DistanceMatrix.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status, result.ErrorMessage); CollectionAssert.AreEqual( new[] { "Alter Sirksfelder Weg 7, 23881 Koberg, Germany" }, result.DestinationAddresses); CollectionAssert.AreEqual( new[] { "Pilsener Str. 16, 92726 Waidhaus, Germany", "Böhmerwaldstraße 19, 93444 Bad Kötzting, Germany" }, result.OriginAddresses); Assert.AreEqual(2, result.Rows.Count()); Assert.AreEqual(DistanceMatrixElementStatusCodes.OK, result.Rows.First().Elements.First().Status); Assert.AreEqual(DistanceMatrixElementStatusCodes.OK, result.Rows.Last().Elements.First().Status); }
public void ShouldReturnValidValueWhenOneOriginAndOneDestinationsSpeciefed() { var request = new DistanceMatrixRequest { Origins = new[] { "49.64265,12.50088" }, Destinations = new[] { "53.64308,10.52726" } }; var result = GoogleMaps.DistanceMatrix.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(DistanceMatrixStatusCodes.OK, result.Status, result.ErrorMessage); CollectionAssert.AreEqual( new [] { "Alter Sirksfelder Weg 7, 23881 Koberg, Germany" }, result.DestinationAddresses); CollectionAssert.AreEqual( new[] { "Pilsener Str. 16, 92726 Waidhaus, Germany" }, result.OriginAddresses); Assert.AreEqual(DistanceMatrixElementStatusCodes.OK, result.Rows.First().Elements.First().Status); Assert.IsNotNull(result.Rows.First().Elements.First().Distance); Assert.IsNotNull(result.Rows.First().Elements.First().Duration); }
public void Directions_VerifyBounds() { var request = new DirectionsRequest { Origin = "Genk, Belgium", Destination = "Brussels, Belgium", TravelMode = TravelMode.Driving }; DirectionsResponse result = GoogleMaps.Directions.Query(request); AssertInconclusive.NotExceedQuota(result); var route = result.Routes.First(); Assert.NotNull(route); Assert.NotNull(route.Bounds); Assert.Greater(route.Bounds.NorthEast.Latitude, 50); Assert.Greater(route.Bounds.NorthEast.Longitude, 3); Assert.Greater(route.Bounds.SouthWest.Latitude, 50); Assert.Greater(route.Bounds.SouthWest.Longitude, 3); Assert.Greater(route.Bounds.Center.Latitude, 50); Assert.Greater(route.Bounds.Center.Longitude, 3); }