Я новичок в разработке приложений для Windows, и я исхожу из андроидного фона. Поэтому у меня есть это приложение, где я показываю список некоторых мест, и при нажатии на любое место пользователю должен быть показан маршрут от его/ее текущего местоположения до места расположения. Я могу добиться этого. Однако при возврате и нажатии на другое место он показывает как предыдущий маршрут до предыдущего местоположения, так и текущий путь.Как убить страницу в разработке Windows Phone 8
Код страницы карты является
namespace MapApper
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private double latitude, longitude;
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
private async void GetRouteAndDirections()
{
Geolocator geolocator = new Geolocator();
Geoposition geoposition = null;
geoposition = await geolocator.GetGeopositionAsync();
// Start at Microsoft in Redmond, Washington.
BasicGeoposition startLocation = new BasicGeoposition();
startLocation.Latitude = geoposition.Coordinate.Latitude;
startLocation.Longitude = geoposition.Coordinate.Longitude;
Geopoint startPoint = new Geopoint(startLocation);
// End at the city of Seattle, Washington.
BasicGeoposition endLocation = new BasicGeoposition();
endLocation.Latitude = latitude;
endLocation.Longitude = longitude;
Geopoint endPoint = new Geopoint(endLocation);
// Get the route between the points.
MapRouteFinderResult routeResult =
await MapRouteFinder.GetDrivingRouteAsync(
startPoint,
endPoint,
MapRouteOptimization.Time,
MapRouteRestrictions.None);
textblock.Text = routeResult.Status.ToString()+latitude+longitude;
if (routeResult.Status == MapRouteFinderStatus.Success)
{
// Use the route to initialize a MapRouteView.
MapRouteView viewOfRoute = new MapRouteView(routeResult.Route);
viewOfRoute.RouteColor = Colors.Yellow;
viewOfRoute.OutlineColor = Colors.Black;
// Add the new MapRouteView to the Routes collection
// of the MapControl.
mapper.Routes.Add(viewOfRoute);
// Fit the MapControl to the route.
await mapper.TrySetViewBoundsAsync(
routeResult.Route.BoundingBox,
null,
Windows.UI.Xaml.Controls.Maps.MapAnimationKind.None);
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Prepare page for display here.
textblock.Text = "EnteringOn";
show s = (show)e.Parameter;
latitude = s.latitude;
longitude = s.longitude;
GetRouteAndDirections();
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
// TODO: If your application contains multiple pages, ensure that you are
// handling the hardware Back button by registering for the
// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
// If you are using the NavigationHelper provided by some templates,
// this event is handled for you.
}
private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
e.Handled = true;
if (Frame.CanGoBack)
Frame.GoBack();
}
}
}
Это, как я получаю путь для предыдущего запроса и текущего запроса вместе.
Я ищу что-то вроде Activity.finish()
в андроид, я знаю, как эта технология очень разные.
Вы можете попробовать очистить предыдущий маршрут с чем-то вроде 'mapper.Routes.Clear()' – Umair