/// <summary> /// Loads the saved location data on first navigation, and /// attaches a Geolocator.StatusChanged event handler. /// </summary> protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (App.PageName.Equals("Start Trip")) { bool getPins = await GetPinsForGivenDate(); if (this.ViewModel.CheckedLocations.Count > 0) { oldPin = this.ViewModel.CheckedLocations[0]; oldPin.IsSelected = true; selectedImage.Source = await PhotoHelper.getImageSource(this.ViewModel.CheckedLocations[0].Photo.ImageName); } else if(this.ViewModel.PinnedLocations.Count>0) { oldPin = this.ViewModel.PinnedLocations[0]; } else { oldPin = new LocationPin { DateCreated = HistoryDatePicker.Date, }; } } else if (App.PageName.Equals("End Trip")) { tripItem = e.Parameter as Trip; NameTb.Text = tripItem.Name; shareTb.Text = tripItem.ShareWith; DescTb.Text = tripItem.Description; startDateTb.Text = "End Date"; startPointTb.Text = "End Point"; submitButton.Content = "End Trip"; bool getPins = await GetPinsForGivenDate(); if (this.ViewModel.CheckedLocations.Count > 0) { oldPin = this.ViewModel.CheckedLocations[this.ViewModel.CheckedLocations.Count - 1]; oldPin.IsSelected = true; selectedImage.Source = await PhotoHelper.getImageSource(this.ViewModel.CheckedLocations[this.ViewModel.CheckedLocations.Count - 1].Photo.ImageName); } else if (this.ViewModel.PinnedLocations.Count > 0) { oldPin = this.ViewModel.PinnedLocations[this.ViewModel.PinnedLocations.Count-1]; } else { oldPin = new LocationPin { DateCreated = HistoryDatePicker.Date, }; } } if (e.NavigationMode == NavigationMode.New) { } }
public static async Task<MapRoute> getRoute(LocationPin destinationPin) { if (string.IsNullOrEmpty(destinationPin.Address)) return null; var currenLoc = await GetCurrentLocationAsync(); var routeResultTask = MapRouteFinder.GetDrivingRouteAsync( currenLoc.Geopoint, destinationPin.Geopoint, MapRouteOptimization.TimeWithTraffic, MapRouteRestrictions.None); MapRouteFinderResult routeResult = await routeResultTask; if (routeResult.Status == MapRouteFinderStatus.Success) { destinationPin.CurrentTravelDistance = Math.Round(routeResult.Route.LengthInMeters * 0.00062137, 1); // convert to miles destinationPin.CurrentTravelTime = (int)routeResult.Route.EstimatedDuration.TotalMinutes; if (routeResult.Status == MapRouteFinderStatus.Success) { return routeResult.Route; } } return null; }
private async void PostButton_Click(object sender, RoutedEventArgs e) { var position = App.currentLocation.Position; if (isRandomPhotoLocation) position = LocationHelper.getRandomLocation(App.currentLocation.Position); var item = new LocationPin { Position = position, Photo = new SharedPhoto { ShareWith = contactPickerTb.Text, ImageName = imageName, Description = DescriptionTb.Text, }, IsCheckPoint = true, DateCreated = App.currentLocation.DateCreated }; await localData.InsertLocationDataAsync(item); App.PageName = "TripTrak"; this.Frame.GoBack(); }
private async void HistoryDatePicker_DateChanged(object sender, DatePickerValueChangedEventArgs e) { HistoryDatePicker.IsHitTestVisible = false; HistoryDatePicker.Opacity = 0.5; var hasData = await GetPinsForGivenDate(); if (App.PageName.Equals("Start Trip")) { if (this.ViewModel.CheckedLocations.Count > 0) { oldPin = this.ViewModel.CheckedLocations[0]; oldPin.IsSelected = true; selectedImage.Source = await PhotoHelper.getImageSource(this.ViewModel.CheckedLocations[0].Photo.ImageName); } else if (this.ViewModel.PinnedLocations.Count > 0) { oldPin = this.ViewModel.PinnedLocations[0]; } else { oldPin = new LocationPin { DateCreated = HistoryDatePicker.Date, }; } } else if (App.PageName.Equals("End Trip")) { if (this.ViewModel.CheckedLocations.Count > 0) { oldPin = this.ViewModel.CheckedLocations[this.ViewModel.CheckedLocations.Count - 1]; oldPin.IsSelected = true; selectedImage.Source = await PhotoHelper.getImageSource(this.ViewModel.CheckedLocations[this.ViewModel.CheckedLocations.Count - 1].Photo.ImageName); } else if (this.ViewModel.PinnedLocations.Count > 0) { oldPin = this.ViewModel.PinnedLocations[this.ViewModel.PinnedLocations.Count - 1]; } else { oldPin = new LocationPin { DateCreated = HistoryDatePicker.Date, }; } } HistoryDatePicker.IsHitTestVisible = true; HistoryDatePicker.Opacity = 1; }
private async void checkedPinBtn_Click(object sender, RoutedEventArgs e) { LocationPin btnPin = ((Button)sender).DataContext as LocationPin; oldPin.IsSelected = false; oldPin = btnPin; oldPin.IsSelected = true; await LocationHelper.TryUpdateMissingLocationInfoAsync(btnPin, null); selectedImage.Source = await PhotoHelper.getImageSource(btnPin.Photo.ImageName); }
public int drawPolylines(LocationPin breakColorPin, bool isAddMilestone, MapControl map) { int ret = 0; //remove all current polylines on map map.MapElements.Clear(); //Order points by DateCreated var simpleGeoInDateOrder = this.PinnedLocations.OrderBy(x => x.DateCreated).ToList(); var color = Colors.Blue; double thickness = 3; var Coords = new List<BasicGeoposition>(); bool breakColor = false; //Query Points list to draw Polylines for (int i = 0; i < simpleGeoInDateOrder.Count; i++) { if (simpleGeoInDateOrder[i].IsCheckPoint == true && isAddMilestone) this.MileStoneLocations.Add(simpleGeoInDateOrder[i]); if (Coords.Count == 0) Coords.Add(simpleGeoInDateOrder[i].Position); else if (!breakColor && simpleGeoInDateOrder[i].DateCreated > breakColorPin.DateCreated) { //define polyline MapPolyline mapPolyline = new MapPolyline(); mapPolyline.StrokeColor = color; mapPolyline.StrokeThickness = thickness; mapPolyline.StrokeDashed = true; mapPolyline.Path = new Geopath(Coords); //draw polyline on map map.MapElements.Add(mapPolyline); ret++; //Clear Coords. Coords.Clear(); if (simpleGeoInDateOrder[i].IsCheckPoint == false && isAddMilestone) this.MileStoneLocations.Add(simpleGeoInDateOrder[i]); breakColor = !breakColor; color = Colors.CornflowerBlue; thickness = 2; } else if (simpleGeoInDateOrder[i].DateCreated - simpleGeoInDateOrder[i - 1].DateCreated < TimeSpan.FromMinutes(5) && Coords.Count < 200) { Coords.Add(simpleGeoInDateOrder[i].Position); } else { //define polyline MapPolyline mapPolyline = new MapPolyline(); mapPolyline.StrokeColor = color; mapPolyline.StrokeThickness = thickness; mapPolyline.StrokeDashed = true; mapPolyline.Path = new Geopath(Coords); //draw polyline on map map.MapElements.Add(mapPolyline); ret++; //Clear Coords. Coords.Clear(); if (simpleGeoInDateOrder[i].IsCheckPoint == false && isAddMilestone) this.MileStoneLocations.Add(simpleGeoInDateOrder[i]); } } //draw last Polyline on map if (Coords.Count > 1) { MapPolyline lastPolyline = new MapPolyline(); lastPolyline.StrokeColor = color; lastPolyline.StrokeThickness = thickness; lastPolyline.StrokeDashed = true; lastPolyline.Path = new Geopath(Coords); //draw polyline on map map.MapElements.Add(lastPolyline); ret++; } return ret; }
/// <summary> /// Attempts to update either the address or the coordinates of the specified location /// if the other value is missing, using the specified current location to provide /// context for prioritizing multiple locations returned for an address. /// </summary> /// <param name="location">The location to update.</param> /// <param name="currentLocation">The current location.</param> public static async Task<bool> TryUpdateMissingLocationInfoAsync(LocationPin location, LocationPin currentLocation) { bool hasNoAddress = String.IsNullOrEmpty(location.Address); if (location.Photo == null) location.Photo = new SharedPhoto(); if (!hasNoAddress) return true; else if (location.Position.Latitude == 0 && location.Position.Longitude == 0) { return false; } var results = await MapLocationFinder.FindLocationsAtAsync(location.Geopoint); if (results.Status == MapLocationFinderStatus.Success && results.Locations.Count > 0) { var result = results.Locations.First(); //This will re-allocate the Position to that particular address. // location.Position = result.Point.Position; location.Address = result.Address.FormattedAddress; if (String.IsNullOrEmpty(location.Name)) location.Name = result.Address.Town; // Sometimes the returned address is poorly formatted. This fixes one of the issues. if (location.Address.Trim().StartsWith(",")) location.Address = location.Address.Trim().Substring(1).Trim(); return true; } else { return false; } }
/// <summary> /// Launches the Maps app and displays the route from the current location /// to the specified location. /// </summary> /// <param name="location">The location to display the route to.</param> public static async Task ShowRouteToLocationInMapsAppAsync(LocationPin location, LocationPin currentLocation) { var mapUri = new Uri("bingmaps:?trfc=1&rtp=" + $"pos.{currentLocation.Position.Latitude}_{currentLocation.Position.Longitude}~" + $"pos.{location.Position.Latitude}_{location.Position.Longitude}"); await Windows.System.Launcher.LaunchUriAsync(mapUri); }