2016-03-04 45 views
0

我正在开发Windows Phone中的Silverlight 8.1中,我想设置使用this链接代码当前位置和硬编码的目的地之间的路径的应用程序:的InnerException = {“异常来自HRESULT:0x8004231C”}

private async void GetCoordinates() 
     { 
      Geolocator myGeolocator = new Geolocator(); 
      myGeolocator.DesiredAccuracyInMeters = 50; 
      Geoposition myposition = null; 
      try 
      { 
       myposition = await myGeolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1),TimeSpan.FromSeconds(50)); 
       Geocoordinate myGeocoordinate = myposition.Coordinate; 
       GeoCoordinate myGeoCoordinate = CoordinateConverter.ConvertGeocoordinate(myGeocoordinate); 
       mycoordinates.Add(new GeoCoordinate(myGeoCoordinate.Latitude, myGeoCoordinate.Longitude)); 
       locationmap.Center = myGeoCoordinate; 
       locationmap.ZoomLevel = 13; 

       Mygeocodequery = new GeocodeQuery(); 
       Mygeocodequery.SearchTerm = "Seattle, WA"; 
       Mygeocodequery.GeoCoordinate = new GeoCoordinate(myGeoCoordinate.Latitude, myGeoCoordinate.Longitude); 
       Mygeocodequery.QueryCompleted += Mygeocodequery_Querycompleted; 
       Mygeocodequery.QueryAsync(); 
      } 
      catch (UnauthorizedAccessException) 
      { 
       MessageBox.Show("Location is disabled in phone settings or capabilities are not checked."); 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
     } 

     private 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.QueryAsync(); 
       Mygeocodequery.Dispose(); 
      } 
     } 

     private void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e) 
     { 
      try 
      { 
        **Route MyRoute = e.Result;** 
        MapRoute MyMapRoute = new MapRoute(MyRoute); 
        locationmap.AddRoute(MyMapRoute); 
        MyQuery.Dispose(); 
      } 
      catch (TargetInvocationException ex) 
      { 
       MessageBox.Show(ex.InnerException.Message); 
      } 
     } 

有时候工作正常,但有时我得到这个内部异常如TargetInvocationException Exception from HRESULT: 0x8004231C

上线高亮请让我知道我应该怎么办?

回答

0

问题是唯一的,因为我已经跳过步骤写在地图控制

private void locationmap_Loaded(object sender, RoutedEventArgs e) 
    { 
     Microsoft.Phone.Maps.MapsSettings.ApplicationContext.ApplicationId = "yourapplicationID"; 
     Microsoft.Phone.Maps.MapsSettings.ApplicationContext.AuthenticationToken = "yourauthenticationtoken"; 
    } 

的加载事件下面的代码,如果这个代码添加它正常工作的所有位置。

相关问题