如何在Windows Phone 8.1应用程序中获取和显示路线和方向

时间:2015-06-10 06:03:00

标签: c# windows-phone-8.1

我想在c#中的Windows Phone 8.1应用程序中获取地图和方向上的路线。我正在使用此代码,但它显示"无效的凭据" 请回复

protected async override void OnNavigatedTo(NavigationEventArgs e)
{
    MapService.ServiceToken = "AgyhW8zBh1zs6Umd7H6CZwDUf7jc2YerR2t1dpxQzWLM3nPzZcR3d3jQNXXGg0xw";
    // Start at Microsoft in Redmond, Washington.
    BasicGeoposition startLocation = new BasicGeoposition();
    startLocation.Latitude = 47.643;
    startLocation.Longitude = -122.131;
    Geopoint startPoint = new Geopoint(startLocation);

    // End at the city of Seattle, Washington.
    BasicGeoposition endLocation = new BasicGeoposition();
    endLocation.Latitude = 47.604;
    endLocation.Longitude = -122.329;
    Geopoint endPoint = new Geopoint(endLocation);

    // Get the route between the points.
    MapRouteFinderResult routeResult =
        await MapRouteFinder.GetDrivingRouteAsync(
        startPoint,
        endPoint,
        MapRouteOptimization.Time,
        MapRouteRestrictions.None);

    if (routeResult.Status == MapRouteFinderStatus.Success)
    {
        // Display summary info about the route.
        tbOutputText.Inlines.Add(new Run()
        {
            Text = "Total estimated time (minutes) = " + routeResult.Route.EstimatedDuration.TotalMinutes.ToString()
        });

        tbOutputText.Inlines.Add(new LineBreak());

        tbOutputText.Inlines.Add(new Run()
        {
            Text = "Total length (kilometers) = " + (routeResult.Route.LengthInMeters / 1000).ToString()
        });

        tbOutputText.Inlines.Add(new LineBreak());
        tbOutputText.Inlines.Add(new LineBreak());

        // Display the directions.
        tbOutputText.Inlines.Add(new Run()
        {
            Text = "DIRECTIONS"
        });

        tbOutputText.Inlines.Add(new LineBreak());

        foreach (MapRouteLeg leg in routeResult.Route.Legs)
        {
            foreach (MapRouteManeuver maneuver in leg.Maneuvers)
            {
                tbOutputText.Inlines.Add(new Run()
                {
                    Text = maneuver.InstructionText
                });

                tbOutputText.Inlines.Add(new LineBreak());
             }
        }
    }
    else
    {
        tbOutputText.Text = "A problem occurred: " + routeResult.Status.ToString();
    }
}

0 个答案:

没有答案