我在XAML中编程相当新,而且我正在使用MapControl在Windows Phone 8.1模拟器上创建应用程序。
昨天我想绘制一条路线并按照本教程http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631250.aspx进行操作,并且工作正常。今天我再次运行它,但它一直给我错误消息' InvalidCredentials'与routeResult.Status。我不知道它为什么会出现这个错误。
这是我使用的代码:
public async void SetRouteDirectionsBreda()
{
string beginLocation = "Willemstraat 17 Breda";
string endLocation = "Reigerstraat 2 Breda";
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(beginLocation, map.Center);
MapLocation begin = result.Locations.First();
result = await MapLocationFinder.FindLocationsAsync(endLocation, map.Center);
MapLocation end = result.Locations.First();
List<Geopoint> waypoints = new List<Geopoint>();
waypoints.Add(begin.Point);
// Adding more waypoints later
waypoints.Add(end.Point);
MapRouteFinderResult routeResult = await MapRouteFinder.GetWalkingRouteFromWaypointsAsync(waypoints);
Debug.WriteLine(routeResult.Status); // DEBUG
if (routeResult.Status == MapRouteFinderStatus.Success)
{
MapRouteView viewOfRoute = new MapRouteView(routeResult.Route);
viewOfRoute.RouteColor = Colors.Blue;
viewOfRoute.OutlineColor = Colors.Black;
map.Routes.Add(viewOfRoute);
await map.TrySetViewBoundsAsync(routeResult.Route.BoundingBox, null, MapAnimationKind.Bow);
}
else
{
throw new Exception(routeResult.Status.ToString());
}
}
答案 0 :(得分:1)
您应该在xaml页面中添加地图服务令牌,并将您的应用程序ID添加到包清单中。
您可以在以下链接中找到有关将mapservicetoken添加到应用程序的所有信息。 http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn741528.aspx