/// <summary>
        /// Handles clicks to set waypoint as destination
        /// </summary>
        private void SetArrivalWaypoint_Click(object sender, RoutedEventArgs e)
        {
            var location = ((MenuFlyoutItem)sender).DataContext as LocationData;

            RouteWaypoints.Add(location);
            RouteDirectionSplitView.IsPaneOpen = true;
        }
        /// <summary>
        /// Handles clicks to the Show Route button and display
        /// the route to the selected location from the user's current position.
        /// </summary>
        private void ShowRouteButton_Click(object sender, RoutedEventArgs e)
        {
            var location = GetLocation(sender as Button);

            RouteWaypoints.Clear();
            RouteWaypoints.Insert(0, MappedLocations[0]);
            RouteWaypoints.Add(location);

            RouteDirectionSplitView.IsPaneOpen = true;
        }
        /// <summary>
        /// Updates the UI to account for the user's current position, if available,
        /// resetting the MapControl bounds and refreshing the travel info.
        /// </summary>
        /// <param name="isGeolocatorReady">false if the Geolocator is known to be unavailable; otherwise, true.</param>
        /// <returns></returns>
        private async Task ResetViewAsync(bool isGeolocatorReady = true)
        {
            LocationData currentLocation = null;

            if (isGeolocatorReady)
            {
                currentLocation = await GetCurrentLocationAsync();
            }

            if (currentLocation != null)
            {
                if (MappedLocations.Count > 0 && MappedLocations[0].IsCurrentLocation)
                {
                    MappedLocations.RemoveAt(0);
                }

                await LocationHelper.TryUpdateMissingLocationInfoAsync(currentLocation, "Current Location");

                MappedLocations.Insert(0, new LocationData {
                    Name = "Current Location", Position = currentLocation.Position, IsCurrentLocation = true
                });
                RouteWaypoints.Insert(0, currentLocation);
            }

            // Set the current view of the map control.
            var positions = Locations.Select(loc => loc.Position).ToList();

            if (currentLocation != null)
            {
                positions.Insert(0, currentLocation.Position);
            }

            if (positions.Count > 0)
            {
                bool isSuccessful = await SetViewBoundsAsync(positions);

                if (isSuccessful && positions.Count < 2)
                {
                    MyMap.ZoomLevel = 15;
                }
                else if (!isSuccessful && positions.Count > 0)
                {
                    MyMap.Center    = new Geopoint(positions[0]);
                    MyMap.ZoomLevel = 15;
                }
            }
        }
        private void searchBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            string tag = ((AutoSuggestBox)sender).Tag.ToString();

            var selected = args.SelectedItem as Result;

            LocationData location = new LocationData()
            {
                Position = new BasicGeoposition()
                {
                    Latitude = selected.position.lat, Longitude = selected.position.lon, Altitude = 50
                }
            };

            location.Name             = LocationHelper.ConstructStringFromAddress(selected.address, "name", null);
            location.Address          = LocationHelper.ConstructStringFromAddress(selected.address, "address", null);
            location.FormattedAddress = LocationHelper.ConstructStringFromAddress(selected.address, "full", null);

            if (String.IsNullOrWhiteSpace(location.Name))
            {
                location.Name = selected.position.lat.ToString("0.000000, ") + selected.position.lon.ToString("0.000000");
            }

            if (selected.poi != null)
            {
                location.Name = selected.poi.name;
            }

            EditNewLocation(location);

            if (tag == "main")
            {
                mainSearchBox.Text = string.Empty;
            }
            else
            {
                RouteWaypoints.Add(location);
                WayPointSearch.Text                   = string.Empty;
                AddRouteWayPointGrid.Visibility       = Visibility.Collapsed;
                AddRouteWayPointButtonGrid.Visibility = Visibility.Visible;
            }
        }
        /// <summary>
        /// Search routes to selected destination/waypoints
        /// </summary>
        private async void GetRouteDirections()
        {
            if (RouteDatas == null)
            {
                return;
            }

            if (RouteDatas.Count > 0)
            {
                RouteDatas.Clear();
            }

            if (RouteWaypoints.Count < 2)
            {
                return;
            }

            List <BasicGeoposition> pts = RouteWaypoints.Select(loc => loc.Position).ToList();

            DateTime dateTime = DateTime.Now.AddMinutes(1);

            if ((leaveatButton.IsChecked.Value) || (arrivebyButton.IsChecked.Value))
            {
                var dts = calendarView.SelectedDates.ToList();
                dateTime = dts[0].DateTime.Date.AddMinutes(timePicker.SelectedTime.Value.TotalMinutes);
            }

            var avoids = GetAvoids();

            var language = (LanguageComboBox.SelectedItem as ComboBoxItem).Tag.ToString();

            RouteDirectionsResponse results = new RouteDirectionsResponse();

            if (leaveatButton.IsChecked.Value || leaveatButton.IsChecked.Value)
            {
                results = await LocationHelper.GetRouteDirections(pts, language, travelMode, avoids, routeType, RouteOptionsCountComboBox.SelectedIndex, dateTime, null);
            }
            else
            {
                results = await LocationHelper.GetRouteDirections(pts, language, travelMode, avoids, routeType, RouteOptionsCountComboBox.SelectedIndex, null, dateTime);
            }

            if (results == null)
            {
                return;
            }

            foreach (var route in results.routes)
            {
                var routedata = new RouteData()
                {
                    Route              = route,
                    IsLeaveNow         = leaveNowButton.IsChecked.Value,
                    IsArriveBy         = arrivebyButton.IsChecked.Value,
                    IsLeaveAt          = leaveatButton.IsChecked.Value,
                    IsShowed           = false,
                    StartLocationLable = RouteWaypoints[0].Name,
                    EndLocationLabel   = RouteWaypoints[RouteWaypoints.Count - 1].Name
                };

                RouteDatas.Add(routedata);
            }
        }
        /// <summary>
        /// Handles clicks to remove waypoint from RouteWaypoints list
        /// </summary>
        private void RemoveWaypointButton_Click(object sender, RoutedEventArgs e)
        {
            var location = ((Button)sender).DataContext as LocationData;

            RouteWaypoints.Remove(location);
        }