Exemple #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.HotDogListView);
            lat      = Intent.GetDoubleExtra("latitude", 0.0);
            longi    = Intent.GetDoubleExtra("longitude", 0.0);
            lwhotdog = FindViewById <ListView>(Resource.Id.hotDogListView);
            string      url  = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + lat + "," + longi + "&types=point_of_interest&radius=100000&sensor=false&key=AIzaSyCrMlsuYQlYLpiwHDes4gsxJlu2IcoyJ7w";
            Rootobject1 Data = FetchWeatherAsync(url);

            lwhotdog.Adapter           = new HotDogAdapter(this, Data.results);
            lwhotdog.FastScrollEnabled = true;
        }
        // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.

        // Connect to the service endpoint using HttpWebRequest
        public string[] WeatherInfo(string city)
        {
            string[] answer1 = new string[6];
            // return results;
            try
            {
                // Connect to the service endpoint using HttpWebRequest
                //String city = "Tempe";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://5dayweather.org/api.php?city=" + city);

                // Use Default credentials and get the response
                request.Credentials = CredentialCache.DefaultCredentials;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                // Get the stream containing content, Open the stream using a StreamReader and convert the content into string
                Stream       receiveStream = response.GetResponseStream();
                StreamReader readStream    = new StreamReader(receiveStream, Encoding.UTF8);
                string       content       = readStream.ReadToEnd();

                // Reference for the above code: https://docs.microsoft.com/en-us/dotnet/framework/network-programming/how-to-request-data-using-the-webrequest-class



                Rootobject1 res = JsonConvert.DeserializeObject <Rootobject1>(content);
                answer1[0] = res.data.location;
                answer1[1] = res.data.skytext;
                answer1[2] = res.data.temperature;
                answer1[3] = res.data.humidity;
                answer1[4] = res.data.wind;
                answer1[5] = res.data.date + " & " + res.data.day;

                return(answer1);
            }
            catch (Exception e)
            {
                answer1[0] = "error";
                answer1[1] = e.Message.ToString();
                return(answer1);
            }
        }
        private async void Vvvvvvvvv_Click(object sender, EventArgs e)
        {
            string url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + lat + "," + longi + "&types=point_of_interest&radius=100000&sensor=false&key=AIzaSyCrMlsuYQlYLpiwHDes4gsxJlu2IcoyJ7w";


            AlphaAnimation AlphaAnimation = new AlphaAnimation(0f, 1f);

            AlphaAnimation.Duration = 200;
            mProgressBar.Animation  = AlphaAnimation;
            mProgressBar.Visibility = Android.Views.ViewStates.Visible;


            //var progressDialog = ProgressDialog.Show(this, "Please wait...", "Checking POI of the Location", true);
            //new Thread(new ThreadStart(delegate
            //{

            //})).Start();
            Rootobject1 Data = await FetchWeatherAsync(url);



            var contactsAdapter  = new StreamListAdapter(this, Data.results);
            var contactsListView = FindViewById <ListView>(Resource.Id.ContactsListView);

            contactsListView.Adapter = contactsAdapter;
            // progressDialog.Hide();
            AlphaAnimation betaAnimation = new AlphaAnimation(0f, 1f);

            betaAnimation.Duration  = 200;
            mProgressBar.Animation  = betaAnimation;
            mProgressBar.Visibility = Android.Views.ViewStates.Gone;

            _addressText.Visibility       = ViewStates.Gone;
            _locationText.Visibility      = ViewStates.Gone;
            get_address_button.Visibility = ViewStates.Gone;
            get_POI.Visibility            = ViewStates.Gone;
            poi.Visibility = ViewStates.Gone;
        }
        private async Task FirstStep()
        {
            var accessStatus = await Geolocator.RequestAccessAsync();

            BasicGeoposition baspos = new BasicGeoposition();

            switch (accessStatus)
            {
            case GeolocationAccessStatus.Allowed:
            {
                Geolocator geolocator = new Geolocator {
                    DesiredAccuracyInMeters = 0
                };
                Geoposition pos = await geolocator.GetGeopositionAsync();

                myLocation = pos.Coordinate.Point;
                baspos     = myLocation.Position;
                baspos     = PositionTransform.Transfrom(baspos);
                myLocation = new Geopoint(baspos);
                UIElement marker = PointMeMarker();
                MyMap.Children.Add(marker);
                MapControl.SetLocation(marker, myLocation);
                MyMap.Center           = myLocation;
                MyMap.LandmarksVisible = true;
                break;
            }

            case GeolocationAccessStatus.Denied:
            {
                var dialog = new MessageDialog("已拒绝程序对位置的访问权,请至设置-隐私-位置中打开本程序的位置访问权限", "异常提示");
                dialog.Commands.Add(new UICommand("确定", cmd => { }));
                var a = await dialog.ShowAsync();

                bool result = await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));

                return;
            }

            case GeolocationAccessStatus.Unspecified:
            {
                var dialog = new MessageDialog("未指明程序对位置的访问权,请至设置-隐私-位置中打开本程序的位置访问权限", "异常提示");
                dialog.Commands.Add(new UICommand("确定", cmd => { }));
                var a = await dialog.ShowAsync();

                bool result = await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));

                return;
            }
            }
            string position = baspos.Longitude + "," + baspos.Latitude;
            string json     = null;

            try
            {
                json = await Httprequest.HttpRequest.GetPositionSearchRequest(position, SerchRange);
            }
            catch (HttpRequestException)
            {
                var dialog = new MessageDialog("周边检索异常(未能成功发送请求)", "异常提示");
                dialog.Commands.Add(new UICommand("确定", cmd => { }));
                var a = await dialog.ShowAsync();
            }
            if (!string.IsNullOrWhiteSpace(json))
            {
                POIResult           = JsonConvert.DeserializeObject <Rootobject1>(json);
                viewmodel.poiresult = POIResult.pois;
                foreach (Pois i in POIResult.pois)
                {
                    Geopoint geo      = LocationToGeoPoint(i.location);
                    MapIcon  mapIcon1 = new MapIcon();
                    mapIcon1.Location = geo;
                    mapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
                    mapIcon1.Title = i.name;
                    MyMap.MapElements.Add(mapIcon1);
                }
            }
        }
Exemple #5
0
        ///<summary>
        /// Effettua la chiamata al Web Service in base al nome cercato, deserializza i dati
        /// e aggiunge gli oggetti creati alla lista temp_list.
        /// </summary>
        /// <param name="FilmName">Contenuto della textBox_search</param>
        /// <param name="PageNumber">Numero di pagina iniziale da visualizzare</param>
        /// <param name="Type">Tipo (Movie, Series, Episode e Game)</param>
        /// <param name="Year">Anno di uscita</param>
        public static async Task <List <Search> > SearchList(string FilmName, int PageNumber, string Type, int Year)
        {
            List <Search> temp_list = new List <Search>();

            MaxFilmPage = 10;

            string query = "";

            if (Type == "" && Year == 0)
            {
                query = "https://www.omdbapi.com/?s=" + FilmName + "&page=" + PageNumber + "&apikey=528b5586";
            }
            else if (Type != "" && Year == 0)
            {
                query = "https://www.omdbapi.com/?s=" + FilmName + "&type=" + Type + "&page=" + PageNumber + "&apikey=528b5586";
            }
            else if (Year != 0 && Type == "")
            {
                query = "https://www.omdbapi.com/?s=" + FilmName + "&y=" + Year + "&page=" + PageNumber + "&apikey=528b5586";
            }
            else if (Year != 0 && Type != "")
            {
                query = "https://www.omdbapi.com/?s=" + FilmName + "&y=" + Year + "&type=" + Type + "&page=" + PageNumber + "&apikey=528b5586";
            }

            using (var client = new HttpClient())
            {
                string risp_JSON = await client.GetStringAsync(query);

                Rootobject1 list_des = JsonConvert.DeserializeObject <Rootobject1>(risp_JSON);

                temp_list.Clear();

                if (list_des.totalResults < 10)
                {
                    MaxFilmPage = list_des.totalResults;
                }

                if (list_des.Response == "True")
                {
                    Total    = list_des.totalResults;
                    Response = true;

                    for (int i = 0; i < MaxFilmPage; i++)
                    {
                        Search Movie_list = new Search
                        {
                            Title  = list_des.Search[i].Title,
                            Poster = list_des.Search[i].Poster,
                            imdbID = list_des.Search[i].imdbID,
                        };
                        temp_list.Add(Movie_list);
                    }

                    // per eliminare i film con lo stesso imdbID
                    // (è commentato perché non risulta chiaro che dopo ci siano altre pagine disponibili)
                    // es: 'Pokemon'
                    // temp_list = temp_list.GroupBy(m => m.imdbID).Select(group => group.First()).ToList();
                }
                else
                {
                    Response = false;
                }
            }
            return(temp_list);
        }