【发布时间】: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());
}
}
也许有人有类似的问题并可以提供帮助?
【问题讨论】:
标签: c# windows-phone-8 geolocation maps