public async Task <GooglePlacesResult> DecodeAddress(string placeId) { if (string.IsNullOrEmpty(placeId)) { return(null); } string url = string.Format(googleMapsUrl, placeId, apiKey); GMapObject jsonData = null; using (var client = new HttpClient()) { var data = await client.GetStringAsync(url); jsonData = JsonConvert.DeserializeObject <GMapObject>(data); } var doc = new XDocument(); var businessResults = jsonData.result; var addressComponents = businessResults.address_components.Where(e => e.types != null); var res = new GooglePlacesResult { Name = businessResults.name, Street = RetrieveStreetName(addressComponents), Number = RetrieveStreetNumber(addressComponents), City = RetrieveCity(addressComponents), Country = RetrieveCountry(addressComponents) }; return(res); }
public async Task <GooglePlacesResult> ParsePlacesAsync(string json) { GooglePlacesResult result = new GooglePlacesResult(); try { PlacesResult placeses = await Task.Run(() => JsonConvert.DeserializeObject <PlacesResult>(json)); if (placeses.Status != "OK") { result.IsSucess = false; } foreach (PlaceGoogle googlePlace in placeses.PlacesGoogle) { if (googlePlace.Photos != null) { result.Places.Add(ConvertToPlace(googlePlace)); } } result.BucketId = placeses.NextPageToken; return(result); } catch { result.IsSucess = false; return(result); } }
public HttpClient Get(string requestPostcode = "CV12WT", string responseTown = "Coventry") { var response = new GooglePlacesResult { Results = new[] { new Result { FormattedAddress = $"Test Street, {responseTown} {requestPostcode}" } }, Status = "OK" }; return(CreateClient(response, "https://example.com/place/textsearch/json?region=uk&radius=1&key=TEST_KEY&query=CV12WT")); }