Beispiel #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            _loadDataButton = UIButton.FromType(UIButtonType.RoundedRect);
            _loadDataButton.SetTitle("Hent sanntidsdata", UIControlState.Normal);
            _loadDataButton.Frame = new RectangleF(10, 10, View.Bounds.Width - 20, 50);

            _result = new UITextView(new RectangleF(10, 70, View.Bounds.Width - 20, View.Bounds.Height - 80));
            _result.Font = UIFont.FromName("Arial", 14);
            _result.Editable = false;

            _activityIndicator = new UIActivityIndicatorView(new RectangleF(View.Bounds.Width / 2 - 20, View.Bounds.Height / 2 - 20, 40, 40));
            _activityIndicator.AutoresizingMask = UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin;
            _activityIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge;

            View.AddSubview(_activityIndicator);
            View.AddSubview(_loadDataButton);
            View.AddSubview(_result);

            View.BackgroundColor = UIColor.DarkGray;

            _loadDataButton.TouchUpInside += delegate(object sender, EventArgs e) {
                if(_location != null)
                {
                    _activityIndicator.StartAnimating();
                    _result.Text = "Jobber..." + Environment.NewLine + Environment.NewLine;
                    var coordinate = new GeographicCoordinate(_location.Latitude, _location.Longtitude);
                    ThreadPool.QueueUserWorkItem(o => _sanntid.GetNearbyStops(coordinate, BusStopsLoaded));
                }
            };

            _gpsService.LocationChanged = location => _location = location;
            _gpsService.Start();
        }
Beispiel #2
0
 public BusStop(string id, string stopCode, string name, GeographicCoordinate location)
 {
     Id = id;
     StopCode = stopCode;
     Name = name;
     Location = location;
 }
Beispiel #3
0
 public void GetNearbyStops(GeographicCoordinate location, Action<List<BusStop>> callback)
 {
     GetBusStopList(stops =>
     {
         var nearbyStops = stops
             .OrderBy(s => RelativeDistance(s.Location, location))
             .Take(NumNearbyStops)
             .ToList();
         callback(nearbyStops);
     });
 }
Beispiel #4
0
        private static double RelativeDistance(GeographicCoordinate c1, GeographicCoordinate c2)
        {
            if (c1 == null || c2 == null)
            {
                return double.MaxValue;
            }

            var dlat = c1.Latitude - c2.Latitude;
            var dlon = c1.Longtitude - c2.Longtitude;

            return Math.Sqrt(dlat * dlat + dlon * dlon);
        }
Beispiel #5
0
 public BusStop()
 {
     Location = new GeographicCoordinate(0,0);
 }
Beispiel #6
0
        /*
        * LatLonToUTMXY
        *
        * Converts a latitude/longitude pair to x and y coordinates in the
        * Universal Transverse Mercator projection.
        *
        * Inputs:
        *   lat - Latitude of the point, in radians.
        *   lon - Longitude of the point, in radians.
        *   zone - UTM zone to be used for calculating values for x and y.
        *          If zone is less than 1 or greater than 60, the routine
        *          will determine the appropriate zone from the value of lon.
        *
        * Outputs:
        *   xy - A 2-element array where the UTM x and y values will be stored.
        *
        * Returns:
        *   The UTM zone used for calculating the values of x and y.
        *
        */
        public CartecianCoordinate LatLonToUtmXy(GeographicCoordinate latLon, int zone)
        {
            var coordinate = MapLatLonToXy(latLon.Latitude, latLon.Longtitude, UtmCentralMeridian(zone));

            /* Adjust easting and northing for UTM system. */
            var x = coordinate.X * UTMScaleFactor + 500000.0;
            var y = coordinate.Y * UTMScaleFactor;
            if (y < 0.0)
                y += 10000000.0;

            return new CartecianCoordinate(x,y);
        }