在 Windows Phone 8.0 地图上绘制路线的问题 - 0x8004231C
Posted
技术标签:
【中文标题】在 Windows Phone 8.0 地图上绘制路线的问题 - 0x8004231C【英文标题】:Issue with drawing routes on Windows Phone 8.0 maps - 0x8004231C 【发布时间】:2015-04-26 04:55:21 【问题描述】:我想创建一个应用程序来显示从我的位置到某个所需点的路线。问题是它有时有效(在某些位置绘制路线)但在某些情况下我收到此错误:
"System.Runtime.InteropServices.COMException (0x8004231C): Excepion from HRESULT: 0x8004231C.
此外,我还遵循了此处的教程:https://msdn.microsoft.com/en-us/library/windows/apps/jj244363%28v=vs.105%29.aspx
这是我的代码:
private async void GetCoordinates()
// Get the phone's current location.
Geolocator MyGeolocator = new Geolocator();
MyGeolocator.DesiredAccuracyInMeters = 5;
Geoposition MyGeoPosition = null;
try
MyGeoPosition = await MyGeolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10));
MyCoordinates.Add(new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.Longitude));
Mapka.Center = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.Longitude);
catch (UnauthorizedAccessException)
MessageBox.Show("Location is disabled in phone settings or capabilities are not checked.");
catch (Exception ex)
// Something else happened while acquiring the location.
MessageBox.Show(ex.Message);
Mygeocodequery = new GeocodeQuery();
Mygeocodequery.QueryCompleted += Mygeocodequery_QueryCompleted;
Mygeocodequery.SearchTerm = txt1.Text;
Mygeocodequery.GeoCoordinate = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.Longitude);
Mygeocodequery.QueryAsync();
void Mygeocodequery_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
if (e.Error == null)
MyQuery = new RouteQuery();
MyCoordinates.Add(e.Result[0].GeoCoordinate);
MyQuery.Waypoints = MyCoordinates;
MyQuery.QueryCompleted += MyQuery_QueryCompleted;
MyQuery.RouteOptimization = RouteOptimization.MinimizeDistance;
MyQuery.QueryAsync();
Mygeocodequery.Dispose();
else
MessageBox.Show(e.Error.ToString());
void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
if (e.Error == null)
Route MyRoute = e.Result;
MapRoute MyMapRoute = new MapRoute(MyRoute);
Mapka.AddRoute(MyMapRoute);
Mapka.SetView(MyMapRoute.Route.BoundingBox);
MessageBox.Show(MyMapRoute.Route.LengthInMeters.ToString());
MyQuery.Dispose();
else
MessageBox.Show(e.Error.ToString());
也许有人有类似的问题并可以提供帮助?
【问题讨论】:
【参考方案1】:对我来说很好用:
GeoCoordinate myPosition = null;
MapRoute MyMapRoute = null;
RouteQuery route = null;
private void getRouteTo(GeoCoordinate myPosition, GeoCoordinate destination)
if (MyMapRoute != null)
map.RemoveRoute(MyMapRoute);
MyMapRoute = null;
route = null;
route = new RouteQuery()
TravelMode = TravelMode.Driving,
Waypoints = new List<GeoCoordinate>()
myPosition,
destination
,
RouteOptimization = RouteOptimization.MinimizeTime
;
route.QueryCompleted += routeQuery_QueryCompleted;
route.QueryAsync();
void routeQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
if (e.Error == null)
Route MyRoute = e.Result;
MyMapRoute = new MapRoute(MyRoute);
map.AddRoute(MyMapRoute);
route.Dispose();
【讨论】:
以上是关于在 Windows Phone 8.0 地图上绘制路线的问题 - 0x8004231C的主要内容,如果未能解决你的问题,请参考以下文章
在 32 位操作系统上安装了 windows phone sdk 8.0 但不起作用?
在 Windows Phone 8 Bing 地图上设置图钉 (XAML C#)
windows phone 8 - 如何在地图上显示经度和纬度坐标(当前位置)