コード例 #1
0
        static void Main(string[] args)
        {
            var api = new AirQualityAPI();

            // Test City api.
            var cityResult = api.CityFeed("Plymouth");

            Console.WriteLine("AQI in Plymouth Centre: " + cityResult.data.aqi);
            Console.ReadLine();

            // Test Station api.
            var geoResult = api.GeolocalisedFeed(50.3790705, -4.141894);

            Console.WriteLine("Station Name: " + geoResult.data.city.name);
            Console.ReadLine();

            // Map api.
            var mapResult = api.MapQuery(50.16634316943975, -6.383056640625001, 51.27909868682927, 1.8896484375000002);

            Console.WriteLine("Map Data results: ");
            for (int i = 0; i < mapResult.data.Count; i++)
            {
                Console.WriteLine("ID of station: " + mapResult.data[i].uid);
            }
            Console.ReadLine();

            // Search api.
            var searchResult = api.Search("bangalore");

            Console.WriteLine("Search Data results: ");
            for (int i = 0; i < searchResult.data.Count; i++)
            {
                Console.WriteLine("Names of search stations: " + searchResult.data[i].station.name);
            }
            Console.ReadLine();
        }
コード例 #2
0
        public MapPageCS()
        {
            api = new AirQualityAPI();

            customMap = new CustomMap {
                MapType         = MapType.Street,
                WidthRequest    = App.ScreenWidth,
                HeightRequest   = 400,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            resultsLabel = new Label
            {
                Text            = "",
                VerticalOptions = LayoutOptions.FillAndExpand,
                FontSize        = 20
            };

            searchBar = new SearchBar
            {
                Placeholder       = "Search for location",
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                SearchCommand     = new Command(() => { resultsLabel.Text = "Result: " + searchBar.Text + " is what you asked for\n Here is a new piece of data!"; })
            };

            // Get user's current location.
            Task.Run(async() => { await GetUserPositionAsync(); });
            while (userLat == 0.0 || userLong == 0.0)
            {
            }

            // Gets the nearest air quality station.
            Console.WriteLine(string.Format("LAT:{0}, LONG: {1}", userLat, userLong));
            var      geoResult       = api.GeolocalisedFeed(userLat, userLong);
            Position stationPosition = new Position(geoResult.data.city.geo[0], geoResult.data.city.geo[1]);
            //Position position = new Position(50.3792423, -4.1401285);
            var closestStationPin = new Pin
            {
                Type     = PinType.Place,
                Position = stationPosition,
                Label    = geoResult.data.city.name,
                Address  = string.Format("Touch me to view Health Alert", geoResult.data.aqi)
            };

            closestStationPin.Clicked += (sender, e) =>
            {
                DisplayAlert(string.Format("{0} - Health Alert", geoResult.data.city.name), string.Format("Air Quality Index is {0}", geoResult.data.aqi), "OK");
            };

            // Create the heatmap for the station and give it the air quality index to
            // evaluate the colour to show.
            customMap.Circle = new CustomCircle(geoResult.data.aqi, stationPosition);

            //var position = new Position (37.79752, -122.40183);
            //customMap.Circle = new CustomCircle {
            //	Position = position,
            //	Radius = 1000
            //};

            customMap.Pins.Add(closestStationPin);

            customMap.MoveToRegion(MapSpan.FromCenterAndRadius(stationPosition, Distance.FromMiles(1.0)));

            //Content = customMap;
            Content = new StackLayout {
                Spacing  = 0,
                Children =
                {
                    searchBar,
                    new ScrollView
                    {
                        Content         = resultsLabel,
                        VerticalOptions = LayoutOptions.FillAndExpand
                    },
                    customMap
                }
            };
        }