public void ReturnsNearbySearchRequest() { if (ApiKey == "") { Assert.Inconclusive("API key not specified"); } var request = new PlacesRequest { ApiKey = ApiKey, Keyword = "pizza", Radius = 10000, Location = new Location(47.611162, -122.337644), //Seattle, Washington, USA Sensor = false, }; PlacesResponse result = GoogleMaps.Places.Query(request); if (result.Status == GoogleMapsApi.Entities.Places.Response.Status.OVER_QUERY_LIMIT) { Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit."); } Assert.AreEqual(GoogleMapsApi.Entities.Places.Response.Status.OK, result.Status); Assert.IsTrue(result.Results.Count() > 5); var correctPizzaPlace = result.Results.Where(t => t.Name.Contains("Pagliacci")); Assert.IsTrue(correctPizzaPlace != null && correctPizzaPlace.Count() > 0); }
/// <summary> /// Find a place by non-Place ID, e.g. PVID. /// </summary> /// <param name="request"></param> /// <returns>Redirect link to the place resource with context added.</returns> public async Task <Place> LookupPlaces(PlacesRequest request) { InitServiceParams(request); var rawPlaces = await GetRawPlaces(GetPlacesSearchQuery(request, "/places/lookup")); var response = JsonConvert.DeserializeObject <Place>(rawPlaces); return(response); }
public void BrowsePlacesFound() { var request = new PlacesRequest { At = "52.531,13.3843" }; var response = placesService.BrowsePlaces(request).Result; Assert.IsTrue(response.Count > 0); }
public void LookupPlacesFound() { var request = new PlacesRequest { Source = "sharing", PlaceId = "276u33db-bae64cc3795443a381643b996f02a2a5" }; var response = placesService.LookupPlaces(request).Result; Assert.IsTrue(response != null); }
public void DiscoverSearchPlacesFound() { var request = new PlacesRequest { Q = "antipodes", At = "52.531,13.3843" }; var response = placesService.DiscoverSearchPlaces(request).Result; Assert.IsTrue(response.Count > 0); }
/// <summary> /// Find places with certain categories around a location sorted by distance /// </summary> /// <param name="request"></param> /// <returns>Sets of places within a specific location context sorted by distance.</returns> public async Task <List <Place> > BrowsePlaces(PlacesRequest request) { InitServiceParams(request); var rawPlaces = await GetRawPlaces(GetPlacesSearchQuery(request, "/browse")); var response = JsonConvert.DeserializeObject <PlacesResponse>(rawPlaces); return(response.Results.Places); }
public string getAdress() { PlacesRequest place = new PlacesRequest() { Location = new GoogleMapsApi.Entities.Common.Location(this.lat, this.lon), Radius = 20 }; place.ApiKey = this.API_KEY; var response = GoogleMapsApi.GoogleMaps.Places.Query(place); return(response.Results.First().Name); }
public async Task <ContentResult> Get(PlacesRequest request) { if (string.IsNullOrEmpty(request.Language) || request.Location == null) { return(Content(JsonConvert.SerializeObject(new PlacesResponse { IsSucess = false }), "application/json")); } string googleApiUrl = $"https://maps.googleapis.com/maps/api/place/nearbysearch/json?key={_Settings.PlacesApiKey}&location={request.Location.Latitude},{request.Location.Longitude}&radius=2000&isopen=true"; // Do Entertainment request to google places API. GooglePlacesResult googlePlacesEntertainmentResult; WebRequest googlePlacesEntertainmentWebRequest = WebRequest.Create($"{googleApiUrl}&keyword=entertainment"); using (WebResponse webResponse = await googlePlacesEntertainmentWebRequest.GetResponseAsync()) { using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream())) { string jsonResponse = streamReader.ReadToEnd(); googlePlacesEntertainmentResult = await _GoogleJsonParser.ParsePlacesAsync(jsonResponse); } } // Do Restaurant request to google places API. GooglePlacesResult googlePlacesRestaurantResult; WebRequest googlePlacesRestaurantWebRequest = WebRequest.Create($"{googleApiUrl}&types=restaurant"); using (WebResponse webResponse = await googlePlacesRestaurantWebRequest.GetResponseAsync()) { using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream())) { string jsonResponse = streamReader.ReadToEnd(); googlePlacesRestaurantResult = await _GoogleJsonParser.ParsePlacesAsync(jsonResponse); } } if (!googlePlacesEntertainmentResult.IsSucess || !googlePlacesRestaurantResult.IsSucess) { return(Content(JsonConvert.SerializeObject(new PlacesResponse { IsSucess = false }), "application/json")); } PlacesResponse response = new PlacesResponse { BucketId = "place holder", // Combine and suffle Entertainment and Restaurant places. Places = googlePlacesEntertainmentResult.Places.Concat(googlePlacesRestaurantResult.Places).ToList().Shuffle() }; return(Content(JsonConvert.SerializeObject(response), "application/json")); }
public void TestNearbySearchPagination() { if (ApiKey == "") { Assert.Inconclusive("API key not specified"); } var request = new PlacesRequest { ApiKey = ApiKey, Keyword = "pizza", Radius = 10000, Location = new Location(47.611162, -122.337644), //Seattle, Washington, USA Sensor = false, }; PlacesResponse result = GoogleMaps.Places.Query(request); if (result.Status == GoogleMapsApi.Entities.Places.Response.Status.OVER_QUERY_LIMIT) { Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit."); } Assert.AreEqual(GoogleMapsApi.Entities.Places.Response.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 Sensor = false, PageToken = result.NextPage }; result = GoogleMaps.Places.Query(request); Assert.AreEqual(GoogleMapsApi.Entities.Places.Response.Status.OK, result.Status); //make sure the second page has some results Assert.IsTrue(result.Results != null && result.Results.Count() > 0); //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.IsFalse(result.Results.Any(t => t.Reference == resultFromFirstPage.Reference)); }
public void ReturnsNearbySearchRequest() { var request = new PlacesRequest { ApiKey = ApiKey, Keyword = "pizza", Radius = 10000, Location = new Location(47.611162, -122.337644), //Seattle, Washington, USA }; PlacesResponse result = GoogleMaps.Places.Query(request); AssertInconclusive.NotExceedQuota(result); Assert.AreEqual(Status.OK, result.Status); Assert.IsTrue(result.Results.Count() > 5); }
public void TestNearbySearchType() { var request = new PlacesRequest { ApiKey = ApiKey, Radius = 10000, Location = new Location(40.6782552, -73.8671761), // New York Type = "airport" }; PlacesResponse result = GoogleMaps.Places.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 ReturnsNearbySearchRequest() { var request = new PlacesRequest { ApiKey = ApiKey, Keyword = "pizza", Radius = 10000, Location = new Location(47.611162, -122.337644), //Seattle, Washington, USA }; PlacesResponse result = GoogleMaps.Places.Query(request); if (result.Status == GoogleMapsApi.Entities.Places.Response.Status.OVER_QUERY_LIMIT) { Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit."); } Assert.AreEqual(GoogleMapsApi.Entities.Places.Response.Status.OK, result.Status); Assert.IsTrue(result.Results.Count() > 5); }
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 TestNearbySearchType() { var request = new PlacesRequest { ApiKey = ApiKey, Radius = 10000, Location = new Location(64.6247243, 21.0747553), // Skellefteå, Sweden Type = "airport", }; PlacesResponse result = GoogleMaps.Places.Query(request); if (result.Status == GoogleMapsApi.Entities.Places.Response.Status.OVER_QUERY_LIMIT) { Assert.Inconclusive("Cannot run test since you have exceeded your Google API query limit."); } Assert.AreEqual(GoogleMapsApi.Entities.Places.Response.Status.OK, result.Status); Assert.IsTrue(result.Results.Any()); var correctAirport = result.Results.Where(t => t.Name.Contains("Skellefteå Airport")); Assert.IsTrue(correctAirport != null && correctAirport.Any()); }
private async Task <List <Place> > GeneratePlaces() { // Adding loader gif await AddLoaderToView(MainPanel); double?longitude = null; double?latitude = null; // Getting user current location if GPS is on if (CrossGeolocator.Current.IsGeolocationEnabled) { var position = await CrossGeolocator.Current.GetPositionAsync(null, null, false); longitude = position.Longitude; latitude = position.Latitude; } // Creating the request var request = new PlacesRequest() { Language = EnumExtensions.GetDisplayName(Language.English).ToString(), Location = !(longitude.HasValue && latitude.HasValue) ? null : new Location { Latitude = latitude.Value, Longitude = longitude.Value } }; // Removing loader gif RemoveLoaderFromView(MainPanel); var httpAddress = AppSettings.GetValue("PlaceRequestApi"); return((List <Place>)request.Send(httpAddress)); }
private Uri GetPlacesSearchQuery(PlacesRequest request, string resource) { return(new Uri($"{baseUrl}{resource}{request.GetUriParameterString()}")); }
private void InitServiceParams(PlacesRequest request) { request.AppId = appId; request.AppToken = appToken; }
public PlacesResponse GetPlace(PlacesRequest request) { return(new PlacesEngine().GetPlaces(request)); }
public static PlacesResponse GetPlace(PlacesRequest request) { return(MapsAPIEngine.GetPlace(request)); }