Esempio n. 1
0
        async void Calculate()
        {
            byte[]          bitmapData;
            CurrentLocation currentLocation = new CurrentLocation();
            string          location        = await currentLocation.GetLocationAsync();

            GooglePlacesApiData     placesData = new GooglePlacesApiData();
            GooglePlacesApiResponse response   = await placesData.GetApiResponseData("food", location);

            textres.Text  = response.results[0].name;
            textresa.Text = response.results[0].vicinity;
            string restaurantId = response.results[0].place_id;

            using (var stream = new MemoryStream())
            {
                bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream);
                bitmapData = stream.ToArray();
            }
            int percentage = 100;

            // var percentage = await DataService.Upload(bitmapData);
            if (i == 0)
            {
                percentage = 90;
                i++;
            }
            if (i == 1)
            {
                percentage = 54;
                i++;
            }
            if (i == 2)
            {
                percentage = 90;
                i++;
            }

            await DataService.PostScan(percentage, drink, response.results[0].name, response.results[0].vicinity, response.results[0].place_id, textMili.Text, textDrink.Text);

            textper.Text = percentage.ToString();
            double mili;

            mili         = Double.Parse(textMili.Text);
            textmil.Text = (mili * (percentage * 0.01)).ToString();
            Boolean b = await DataService.MaxAlco();

            if (b == true)
            {
                AlertDialog.Builder builder;
                builder = new AlertDialog.Builder(this);
                builder.SetTitle("Too Much Alcohol!!!");
                builder.SetMessage("That's way too much alcohol for you this week...");
                builder.SetCancelable(false);
                builder.SetPositiveButton("OK", delegate { });
                Dialog dialog = builder.Create();
                dialog.Show();
            }
        }
Esempio n. 2
0
        public async Task <GooglePlacesApiResponse> GetApiResponseData(string type, string location)
        {
            HttpClient client = new HttpClient();
            string     url    = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?rankby=distance&location="
                                + location + "&type=" + type + "&key=AIzaSyAoqL_K1g-5kTuinL-60Tmcf9udFtc9SLg";
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url);

            HttpResponseMessage responseMessage = await client.SendAsync(requestMessage);

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

            return(responseData);
        }
Esempio n. 3
0
        /*   async void btnSearchPl_ClickAsync(object sender, System.EventArgs e)
         * {
         *     GooglePlacesApiData googleApi = new GooglePlacesApiData();
         *     GooglePlacesApiResponse response = await googleApi.GetApiResponseData(type.ToLower());
         *     List<Restaurant> restaurantList = new List<Restaurant>();
         *     for(int i=0; i<20; i++)
         *     {
         *         Restaurant res = new Restaurant();
         *         res.Name = response.results[i].name;
         *         res.Address = response.results[i].vicinity;
         *         res.Id = 5;
         *         res.Percentage = 44;
         *         restaurantList.Add(res);
         *     }
         *     listRestaurants.Adapter = new RestaurantAdapter(this, restaurantList);
         * }*/
        async void btnSearchPl_ClickAsync(object sender, System.EventArgs e)
        {
            CurrentLocation currentCoordinate = new CurrentLocation();
            string          location          = await currentCoordinate.GetLocationAsync();

            CurrentLatLng = new LatLng(currentCoordinate.Lat, currentCoordinate.Lng);
            GooglePlacesApiData googleApi = new GooglePlacesApiData();

            response = await googleApi.GetApiResponseData(type.ToLower(), location);

            SetUpMap();

            /*List<Restaurant> restaurantList = new List<Restaurant>();
             * for (int i = 0; i < 20; i++)
             * {
             *  Restaurant res = new Restaurant();
             *  res.Name = response.results[i].name;
             *  res.Address = response.results[i].vicinity;
             *  res.Id = 5;
             *  res.Percentage = 44;
             *  restaurantList.Add(res);
             * }
             * listRestaurants.Adapter = new RestaurantAdapter(this, restaurantList);*/
        }