Beispiel #1
0
        public async Task <Bitmap> GetMapResponseDataAsync(String type, String zoom)
        {
            CurrentCoordinate currentCoordinate = new CurrentCoordinate();

            currentCoordinate.CalculateCurrentCoordinates();
            String currentCoordinates = CoordinatesConverter.GetConvertedCoordinates(currentCoordinate.Latitude, currentCoordinate.Longitude);

            placesList.AddRange(await new NearbyPlacesList().GetNearbyPlacesListAsync(type));
            placesList.ToArray();
            String url = ConfigurationManager.AppSettings["GoogleStaticMapApiUrl"] + "&size=" + mapSize
                         + "&center=" + currentCoordinates + "&zoom=" + zoom
                         + "&" + ConfigurationManager.AppSettings["GoogleStaticMapApiKey"];

            for (int i = 0; i < 5; i++)
            {
                url += "&" + ConfigurationManager.AppSettings["GoogleStaticMapApiMarker"] + (i + 1) + "%7C" + placesList[i].Coordinates;
            }
            Uri             uri          = new Uri(url);
            HttpWebRequest  httpRequest  = (HttpWebRequest)HttpWebRequest.Create(uri);
            HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            Stream          imageStream  = httpResponse.GetResponseStream();
            Bitmap          image        = new Bitmap(imageStream);

            httpResponse.Close();
            imageStream.Close();
            return(image);
        }
        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);
        }
Beispiel #3
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);
        }