コード例 #1
0
        public WeatherForecastAnnotation[] GetForecastAnnotations(MKCoordinateRegion region, int maxCount)
        {
            double longMin = region.Center.Longitude - region.Span.LongitudeDelta / 2.0;
            double longMax = region.Center.Longitude + region.Span.LongitudeDelta / 2.0;
            double latMin  = region.Center.Latitude - region.Span.LatitudeDelta / 2.0;
            double latMax  = region.Center.Latitude + region.Span.LatitudeDelta / 2.0;

            // Query for WeatherForecasts within our specified region
            var results = from item in store.Table <WeatherForecast> ()
                          where (item.Latitude > latMin && item.Latitude <latMax && item.Longitude> longMin && item.Longitude < longMax)
                          orderby item.Latitude
                          orderby item.Longitude
                          select item;

            // Iterate over the results and add them to a list

            var list = new List <WeatherForecastAnnotation> ();

            foreach (var forecast in results)
            {
                list.Add(new WeatherForecastAnnotation(forecast));
            }



            if (list.Count <= maxCount)
            {
                // We got fewer results than the max, so just return what we found
                return(list.ToArray());
            }

            // Calculate a stride so we can get an evenly distributed sampling of the results
            double index = 0.0, stride = (double)(list.Count - 1) / (double)maxCount;
            var    annotations = new WeatherForecastAnnotation [maxCount];

            for (int i = 0; i < maxCount && (int)index < list.Count; i++, index += stride)
            {
                annotations[i] = list[(int)index];
            }

            return(annotations);
        }
コード例 #2
0
		public WeatherForecastAnnotation[] GetForecastAnnotations (MKCoordinateRegion region, int maxCount)
		{
			double longMin = region.Center.Longitude - region.Span.LongitudeDelta / 2.0;
			double longMax = region.Center.Longitude + region.Span.LongitudeDelta / 2.0;
			double latMin = region.Center.Latitude - region.Span.LatitudeDelta / 2.0;
			double latMax = region.Center.Latitude + region.Span.LatitudeDelta / 2.0;

			// Query for WeatherForecasts within our specified region
			var results = from item in store.Table<WeatherForecast> ()
				where (item.Latitude > latMin && item.Latitude < latMax && item.Longitude > longMin && item.Longitude < longMax)
					orderby item.Latitude
					orderby item.Longitude
					select item;

			// Iterate over the results and add them to a list
			var list = new List<WeatherForecastAnnotation> ();
			foreach (var forecast in results)
				list.Add (new WeatherForecastAnnotation (forecast));

			if (list.Count <= maxCount) {
				// We got fewer results than the max, so just return what we found
				return list.ToArray ();
			}

			// Calculate a stride so we can get an evenly distributed sampling of the results
			double index = 0.0, stride = (double) (list.Count - 1) / (double) maxCount;
			var annotations = new WeatherForecastAnnotation [maxCount];

			for (int i = 0; i < maxCount && (int) index < list.Count; i++, index += stride)
				annotations[i] = list[(int) index];

			return annotations;
		}