public async Task <IEnumerable <Geocode> > GetGeocodesForAddress(string address) { GoogleApiRequest request = new GoogleApiRequestBuilder().ToApi(GeocodeApiUri).WithQueryParam("address", address).Build(); GoogleApiResponse response = await this.client.Get(request); return(response.ConvertResults <Geocode>()); }
private async Task <IEnumerable <Place> > GetPlacesNearCoordinateWithPageToken(double latitude, double longitude, double radiusMeters, string pageToken) { string locationArgument = $"{latitude},{longitude}"; GoogleApiRequestBuilder requestBuilder = new GoogleApiRequestBuilder() .ToApi(PlaceApiUri) .ToSubApi(NearbySearchSubApiUri) .WithQueryParam("location", locationArgument) .WithQueryParam("radius", radiusMeters.ToString()); if (pageToken != null) { requestBuilder = requestBuilder.WithQueryParam("pagetoken", pageToken); } GoogleApiRequest request = requestBuilder.Build(); GoogleApiResponse response = await this.client.Get(request); IEnumerable <Place> places = response.ConvertResults <Place>(); if (!string.IsNullOrEmpty(response.NextPageToken)) { await Task.Delay(2000); // I've found that you have to wait a little bit to get the next page. Otherwise, it gives back an "invalid request" response. places = places.Concat(await GetPlacesNearCoordinateWithPageToken(latitude, longitude, radiusMeters, response.NextPageToken)); } return(places); }
public async Task <IEnumerable <Geocode> > GetGeocodesForCoordinate(double latitude, double longitude) { string latlngArgument = $"{latitude},{longitude}"; GoogleApiRequest request = new GoogleApiRequestBuilder().ToApi(GeocodeApiUri).WithQueryParam("latlng", latlngArgument).Build(); GoogleApiResponse response = await this.client.Get(request); return(response.ConvertResults <Geocode>()); }