// make sure the app is still working while the phone is in sleeping mode protected override void OnSleep() { if (Application.Current.Properties.ContainsKey("map")) { map = (GMTEMap)Application.Current.Properties["map"]; } else { map = new GMTEMap() { IsShowingUser = true, HeightRequest = 100, WidthRequest = 960, VerticalOptions = LayoutOptions.FillAndExpand, HasZoomEnabled = true }; } // check geolocation CrossGeolocator.Current.PositionChanged += (o, args) => { // check campus if ((map.CheckInGeofences(args.Position)) && (onCampus == false)) { Device.BeginInvokeOnMainThread(() => { mCurrentCampus = map.InWhichGeofences(args.Position); //DisplayAlert("Welcome to " + mCurrentCampus + "!", "We hope you find your way around!", "Okay"); }); onCampus = true; } else if ((map.CheckInGeofences(args.Position) == false) && (onCampus == true)) { Device.BeginInvokeOnMainThread(() => { //DisplayAlert("Now leaving " + mCurrentCampus, "Did you mean to do that?", "Maybe?"); onCampus = false; mCurrentCampus = ""; }); } // check parking lot if (map.CheckInLotGeofences(args.Position, mCurrentCampus) && (mParked == false) && (inLot == false)) { Device.BeginInvokeOnMainThread(() => { mCurrentLot = map.InWhichLot(args.Position, mCurrentCampus); //DisplayAlert("You are in lot " + mCurrentLot + "!", "We hope you find a spot!", "Okay"); }); inLot = true; } if ((mParked) && (mShown == false)) { Device.BeginInvokeOnMainThread(() => { //DisplayAlert("You Parked!", "We detected that you parked in " + mLotParked, "Okay"); }); mShown = true; } if ((map.InWhichLot(args.Position, mCurrentCampus) != mCurrentLot) && (mCurrentLot != "") && (mTimerStarted == false) && (mParked == false)) { Device.BeginInvokeOnMainThread(() => { //DisplayAlert("Now leaving " + mCurrentLot, "Start parking-detection algorithm", "Start"); }); mLotParked = mCurrentLot; mCurrentLot = ""; mTimerStarted = true; if (map.CheckInLotGeofences(args.Position, mCurrentCampus)) { inLot = true; } else { inLot = false; } //Device.StartTimer(TimeSpan.FromSeconds(.5), new Func<bool>(() => CheckSpeed(args.Position))); } if ((map.CheckInLotGeofences(args.Position, mCurrentCampus) == false) && (mParked == false)) { mCurrentLot = ""; inLot = false; } }; }
public MapPage(string selectedRole, string buildingName, string campusName) { InitializeComponent(); mCampusName = campusName; mBuildingName = buildingName; mRole = selectedRole; this.Title = mBuildingName; if (Application.Current.Properties.ContainsKey("map")) { map = (GMTEMap)Application.Current.Properties["map"]; } else { // Creates campuses objects and draws them map.AddCampus(campusName); // Assigns title of page to building that is to be going to this.Title = buildingName; Task addBuild = map.DrawBuildings(campusName); map.DrawLots(campusName); } string font; switch (Device.RuntimePlatform) { case "iOS": font = "AppleSDGothicNeo-UltraLight"; break; case "Android": font = "Droid Sans Mono"; break; default: font = "Comic Sans MS"; break; } client = new HttpClient(); client.MaxResponseContentBufferSize = 256000; var lotTask = GetLotOrder(); var lotLabel = new Label { FontFamily = font, TextColor = Color.Blue }; var goingToLabel = new Label { FontFamily = font, TextColor = Color.Green, }; lotLabel.SetBinding(Label.TextProperty, new Binding("Lots", stringFormat: "{0}")); goingToLabel.SetBinding(Label.TextProperty, new Binding("GoingTo", stringFormat: "Going to: {0}")); var button = new Button() { Text = "Start Directions!", Font = Font.SystemFontOfSize(NamedSize.Large), FontFamily = font, CommandParameter = new double() }; button.Clicked += OnClicked; button.SetBinding(Button.CommandParameterProperty, new Binding("Pos")); stack.Children.Add(lotLabel); stack.Children.Add(goingToLabel); stack.Children.Add(map); stack.Children.Add(button); stack.BindingContext = new { Lots = "Retrieving closest lots..." }; stack.BindingContext = stack.Children[0].BindingContext; this.Content = stack; Task stackTask = ConvertLots(lotTask); AwaitTask(stackTask); map.SpanToBuilding(buildingName, campusName); StartGeoLocation(); CrossGeolocator.Current.PositionChanged += (o, args) => { if ((map.CheckInGeofences(args.Position)) && (onCampus == false)) { Device.BeginInvokeOnMainThread(() => { mCurrentCampus = map.InWhichGeofences(args.Position); DisplayAlert("Welcome to " + mCurrentCampus + "!", "We hope you find your way around!", "Okay"); DependencyService.Get <ITextToSpeech>().Speak("Welcome to " + mCurrentCampus); onCampus = true; }); } else if ((map.CheckInGeofences(args.Position) == false) && (onCampus == true)) { Device.BeginInvokeOnMainThread(() => { DisplayAlert("Now leaving " + mCurrentCampus, "Did you mean to do that?", "Maybe?"); onCampus = false; mCurrentCampus = ""; }); } if (map.CheckInLotGeofences(args.Position, mCurrentCampus) && (mParked == false) && (inLot == false)) { Device.BeginInvokeOnMainThread(() => { mCurrentLot = map.InWhichLot(args.Position, mCurrentCampus); DisplayAlert("You are in lot " + mCurrentLot + "!", "We hope you find a spot!", "Okay"); DependencyService.Get <ITextToSpeech>().Speak("You are in lot " + mCurrentLot); }); inLot = true; } if ((mParked) && (mShown == false)) { Device.BeginInvokeOnMainThread(() => { DisplayAlert("You Parked!", "We detected that you parked in " + mLotParked, "Okay"); DependencyService.Get <ITextToSpeech>().Speak("You Parked in " + mLotParked); }); mShown = true; } if ((map.InWhichLot(args.Position, mCurrentCampus) != mCurrentLot) && (mCurrentLot != "") && (mTimerStarted == false) && (mParked == false)) { Device.BeginInvokeOnMainThread(() => { DisplayAlert("Now leaving " + mCurrentLot, "Start parking-detection algorithm", "Start"); }); mLotParked = mCurrentLot; mCurrentLot = ""; mTimerStarted = true; if (map.CheckInLotGeofences(args.Position, mCurrentCampus)) { inLot = true; } else { inLot = false; } Device.StartTimer(TimeSpan.FromSeconds(.5), new Func <bool>(() => CheckSpeed(args.Position))); } if ((map.CheckInLotGeofences(args.Position, mCurrentCampus) == false) && (mParked == false)) { mCurrentLot = ""; inLot = false; } }; }