Exemplo n.º 1
0
        public async Task <List <NearbyPlace> > GetNearbyPlacesListAsync(String type)
        {
            GooglePlacesApiData     nearbyPlacesData = new GooglePlacesApiData();
            GooglePlacesApiResponse placesData       = await nearbyPlacesData.GetApiResponseData(type);

            List <NearbyPlace> placesList = new List <NearbyPlace>();

            for (int i = 0; i < 5; i++)
            {
                placesList.Insert(i, new NearbyPlace(placesData.results[i].name, placesData.results[i].vicinity,
                                                     CoordinatesConverter.GetConvertedCoordinates(placesData.results[i].geometry.location.lat,
                                                                                                  placesData.results[i].geometry.location.lng)));
            }
            return(placesList);
        }
Exemplo n.º 2
0
        public async Task <GooglePlacesApiResponse> GetApiResponseData(String type)
        {
            CurrentCoordinate currentCoordinate = new CurrentCoordinate();

            currentCoordinate.CalculateCurrentCoordinates();
            String             currentCoordinates = CoordinatesConverter.GetConvertedCoordinates(currentCoordinate.Latitude, currentCoordinate.Longitude);
            HttpClient         client             = new HttpClient();
            HttpRequestMessage requestMessage     = new HttpRequestMessage(HttpMethod.Get,
                                                                           ConfigurationManager.AppSettings["GooglePlacesApiUrl"] + "&location="
                                                                           + currentCoordinates + "&type=" + type + "&"
                                                                           + ConfigurationManager.AppSettings["GooglePlacesApiKey"]);

            HttpResponseMessage responseMessage = await client.SendAsync(requestMessage);

            GooglePlacesApiResponse responseData = JsonConvert.DeserializeObject <GooglePlacesApiResponse>(await responseMessage.Content.ReadAsStringAsync());

            return(responseData);
        }