2014-01-12 156 views
0

我已經在應用中使用WCF服務。將路由與WCF服務

從1開始繪製從WCF返回的座標時繪製直線。然後畫出錯誤的路徑。當Windows Phone 7正確顯示時,使用折線。

下面顯示的是,我得到錯誤的結果:

我想顯示:

這是我處理繪製代碼:

void wcl_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
{ 
    try 
    { 
     if (string.IsNullOrEmpty(e.Result) || e.Error != null) 
     { 
      MessageBox.Show("Lỗi kết nối! Hãy thử lại"); 
      waitingPage.Visibility = System.Windows.Visibility.Collapsed; 
      return; 
     } 

     XuLyToaDo route = XuLyToaDo.TaoMapRoute(); 
     //Lay ds diem ve 
     string Ketqua = XuLyToaDo.DanhSachDiemVe(e.Result); 
     string[] kq = Ketqua.Split('&'); 

     //Lay thong tin toa do 
     XuLyToaDo routePushpin = XuLyToaDo.TaoMapRoute(); 
     XuLyToaDo routePolyline = XuLyToaDo.TaoMapRoute(); 
     //MessageBox.Show(kq[0]); 
     //MessageBox.Show(kq[1]); 
     //MessageBox.Show(kq[2]); 
     //Tao ds toa do 
     List<GeoCoordinate> lsToaDoPushpin = routePushpin.TaoDSToaDo(kq[0]); 
     List<GeoCoordinate> lsToaDoRoute = routePushpin.TaoDSToaDo(kq[1]); 
     // Lay ds ten duong 
     string[] MangTenDiaChi = routePushpin.TaoDSDuong(kq[2]); 
     if (lsToaDoPushpin == null) 
     { 
      MessageBox.Show("Không có thông tin"); 
      waitingPage.Visibility = System.Windows.Visibility.Collapsed; 
      return; 
     } 
     for (int i = 0; i < lsToaDoPushpin.Count - 1; i++) 
     { 
      AddRoute(lsToaDoPushpin[i], Colors.Blue); 
     } 
     //ve duong di 
     for (int i = 0; i < lsToaDoPushpin.Count - 2; i++) 
     { 
      AddRouteMap(lsToaDoPushpin[i], lsToaDoPushpin[i + 1]); 
     } 
     //ve duong di 
     //MyRouteQuery = new RouteQuery() 
     //{ 
     // TravelMode = TravelMode.Driving, 
     // Waypoints = lsToaDoRoute 

     //}; 
     //MyRouteQuery.QueryCompleted += MyRouteQuery_QueryCompleted; 
     //MyRouteQuery.QueryAsync(); 

     //Them danh sach tram 
     int k = 0; 
     foreach (GeoCoordinate geo in lsToaDoPushpin) 
     { 
      if (k == lsToaDoPushpin.Count() - 1) 
       break; 
      Pushpin pus = new Pushpin(); 
      string str = "Direc_" + k; 
      pus.Template = Maps.App.Current.Resources[str] as ControlTemplate; 
      pus.Tag = k; 
      pus.Content = k.ToString() + ". " + MangTenDiaChi[k]; 
      pus.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(pus_Tap); 
      MyMap.Layers.Add(new MapLayer() 
       { 
       new MapOverlay() 
       { 
        GeoCoordinate = geo, 
        PositionOrigin = new Point(0.5,0.5), 
        Content = pus 
       } 
       }); 
      k++; 
     } 
     MyMap.Center = lsToaDoPushpin[0]; 
     MyMap.ZoomLevel = 15; 
     waitingPage.Visibility = System.Windows.Visibility.Collapsed; 
    } 
    catch (Exception ex) 
    { 
     MessageBox.Show("Lỗi kết nối. Hãy thử lại!!" + ex.Message); 
    } 
} 

private void AddRouteMap(GeoCoordinate g1, GeoCoordinate g2) 
{ 
    List<GeoCoordinate> lsRoute = new List<GeoCoordinate>(); 
    lsRoute.Add(g1); 
    lsRoute.Add(g2); 

    MyRouteQuery = new RouteQuery() 
    { 
     TravelMode = TravelMode.Walking, 
     Waypoints = lsRoute 

    }; 
    MyRouteQuery.QueryCompleted += MyRouteQuery_QueryCompleted; 
    MyRouteQuery.QueryAsync(); 
} 
void MyRouteQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e) 
{ 

    if (e.Error == null) 
    { 

     if (MyMapRoute != null) 
      AddlstMapRoute(MyMapRoute); 
     MyRoute = e.Result; 
     MyMapRoute = new MapRoute(MyRoute); 
     MyMap.AddRoute(MyMapRoute); 

    } 
} 
private void AddlstMapRoute(MapRoute maproute) 
{ 
    lsMapRoute.Add(maproute); 
} 
private void AddRoute(GeoCoordinate geo, Color color) 
{ 

    MyMap.Layers.Add(new MapLayer() 
    { 
     new MapOverlay() 
     { 
      GeoCoordinate = geo, 
      PositionOrigin = new Point(0.5,0.5), 

      Content = new Ellipse 
      { 
       Fill = new SolidColorBrush(color), 
       Width =5, 
       Height = 5 
      } 

     } 
    }); 
} 

void pus_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
{ 
    e.Handled = true; 
    Pushpin pus = sender as Pushpin; 
    ToolTipService.SetToolTip(pus, new ToolTip() 
    { 
     DataContext = pus, 
     Style = Application.Current.Resources["CustomInfoboxStyle"] as Style 
    }); 
    MessageBox.Show(pus.Content.ToString(), "Thông tin trạm", MessageBoxButton.OK); 
} 

這是pl王牌,我創建數據庫:

我該如何解決這個問題?

+0

感謝mod編輯:)!請幫幫我。 – jvinhit

回答

0

我想這是因爲你的旅行模式設置爲走路,谷歌似乎認爲走在那裏是不允許的,所以它採取下一個可能的方式。嘗試改變旅行模式駕駛或左右。

問候lars

+0

不,我得到屬性travelmode =開車!幫我! – jvinhit