private static double MARGIN_OF_ERROR = 10.0; // in m public MapPage() { // map with default centre at NUS var NUSCentre = new Xamarin.Forms.Maps.Position(1.2966, 103.7764); map = new BusMap(MapSpan.FromCenterAndRadius(NUSCentre, Distance.FromKilometers(MEAN_MAP_RADIUS))) { IsShowingUser = true, HeightRequest = 100, WidthRequest = 960, VerticalOptions = LayoutOptions.FillAndExpand }; // add map and slider to stack layout var stack = new StackLayout { Spacing = 0 }; stack.Children.Add(map); Icon = "MapTabIcon.png"; Title = "Map"; Content = stack; // add random buses for testing BusSimulator.DispatchBuses(); // init bus and stop pins UpdatePublicBusPins(); UpdateBusPins(); UpdateStopPins(); }
public MapPage() { // map with default centre at NUS var NUSCenter = new Xamarin.Forms.Maps.Position(1.2966, 103.7764); map = new BusMap( MapSpan.FromCenterAndRadius(NUSCenter, Distance.FromKilometers(DEFAULT_RADIUS))) { IsShowingUser = true, HeightRequest = 100, WidthRequest = 960, VerticalOptions = LayoutOptions.FillAndExpand }; // shift to current location if possible (activate only for device testing) // ShiftToCurrentLocation (); // add pins for each bus stops foreach (BusStop busStop in BusHelper.BusStops.Values) { var description = ""; foreach (string svc in busStop.services) { description += svc + ": " + BusHelper.GetArrivalTiming(busStop.busStopCode, svc) + "\n"; } var pin = new Pin { Type = PinType.Place, Position = new Xamarin.Forms.Maps.Position(busStop.latitude, busStop.longitude), Label = busStop.name + " - " + busStop.busStopCode, Address = description }; var stop = new CustomPin { Pin = pin, Id = "stop", Url = "stop.png" }; map.Pins.Add(pin); map.StopPins.Add(stop); } // slider to change radius from 0.1 - 0.9 km var slider = new Slider(1, 9, 5); slider.ValueChanged += (sender, e) => { var zoomLevel = e.NewValue; // between 1 and 9 currRadius = 1.0 - (zoomLevel / 10.0); map.MoveToRegion(MapSpan.FromCenterAndRadius( map.VisibleRegion.Center, Distance.FromKilometers(currRadius))); }; // add map and slider to stack layout var stack = new StackLayout { Spacing = 0 }; stack.Children.Add(map); stack.Children.Add(slider); Icon = "MapTabIcon.png"; Title = "Map"; Content = stack; // add random buses for testing BusSimulator.DispatchBuses(); // set timer to update bus and current location Device.StartTimer(TimeSpan.FromSeconds(REFRESH_INTERVAL), UpdatePositions); }