使用WCF服务映射路由

时间:2014-01-12 17:56:51

标签: windows-phone-8 map routes here-api

我在应用中使用了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);
}

这是我创建数据库的地方:

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我猜它是因为你的旅行模式设置为步行而谷歌似乎认为在那里行走是不允许的,所以它需要下一个可能的方式。尝试将旅行模式改为驾驶等。

问候lars