none
WPF BING map 在wpf中使用 bing地图 RRS feed

  • 问题

  • 在wpf开发中我想知道如何设置 导航的api 类似百度的  

    var walking = new BMap.WalkingRoute(map, { renderOptions: { map: map, autoViewport: true } });
    function SeekMap(start, end) {
    //start 开始的地点, end 结束的地址
        walking.search(start, end);
    }

    如何设置 bing 地图里面显示中文,

     xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"

    2014年6月6日 7:44

答案

  • 你好,

    >>在wpf开发中我想知道如何设置 导航的api

    你需要使用REST服务,请看此链接:
    #Using the REST Services with .NET
    http://msdn.microsoft.com/en-us/library/jj819168.aspx

    XAML:

    <Grid>
            <m:Map Name="myMap" 
                   Center="-1.968404, 30.036240" 
                   ZoomLevel="10"
                   CredentialsProvider="FillYourKey"
                   Mode="AerialWithLabels" ></m:Map>
    
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom">
                <Label Content="From: " FontWeight="Bold" />
                <TextBox Width="80" Height="20" Name="fromTxb" Text="New York" />
                <Label Content="To: " FontWeight="Bold" />
                <TextBox Width="80" Height="20" Name="toTxb" Text="Seattle" />
                <Button Content="Route" Width="80" Click="RouteButton_Click" />
            </StackPanel>
        </Grid>

    用下述方法从REST请求路径数据:

    private void Route(string start, string end, string key, Action<Response> callback)
    {
                //Culture c = CultureDD.SelectedItem as Culture;
                Uri requestURI = new Uri(string.Format("http://dev.virtualearth.net/REST/V1/Routes/Driving?wp.0={0}&wp.1={1}&rpo=Points&key={2}", Uri.EscapeDataString(start), Uri.EscapeDataString(end), key));
                //QueryURLTbx.Text = requestURI.AbsoluteUri;
                GetResponse(requestURI, callback);
    }
    
            private void GetResponse(Uri uri, Action<Response> callback)
            {
                try
                {
                    HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
                    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                    {
                        using (Stream stream = response.GetResponseStream())
                        {
                            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
    
                            if (callback != null)
                            {
                                callback(ser.ReadObject(stream) as Response);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
    }

    获取会话密钥:

    private void GetKey(Action<string> callback)
    {
                if (callback != null)
                {
                    myMap.CredentialsProvider.GetCredentials((c) =>
                    {
                        callback(c.ApplicationId);
                    });
                }
    }

    绘制路径:

    private void GetRoute(string fromloc, string toloc)
    {
                string to = toloc;//"Seattle";
                string from = fromloc;//"New York";
    
                if (!string.IsNullOrWhiteSpace(from))
                {
                    if (!string.IsNullOrWhiteSpace(to))
                    {
                        GetKey((c) =>
                        {
                            Route(from, to, c, (r) =>
                            {
                                if (r != null &&
                                    r.ResourceSets != null &&
                                    r.ResourceSets.Length > 0 &&
                                    r.ResourceSets[0].Resources != null &&
                                    r.ResourceSets[0].Resources.Length > 0)
                                {
                                    Route route = r.ResourceSets[0].Resources[0] as Route;
    
                                    double[][] routePath = route.RoutePath.Line.Coordinates;
                                    LocationCollection locs = new LocationCollection();
    
                                    for (int i = 0; i < routePath.Length; i++)
                                    {
                                        if (routePath[i].Length >= 2)
                                        {
                                            locs.Add(new Microsoft.Maps.MapControl.WPF.Location(routePath[i][0], routePath[i][1]));
                                        }
                                    }
    
                                    MapPolyline routeLine = new MapPolyline()
                                    {
                                        Locations = locs,
                                        Stroke = new SolidColorBrush(Colors.Red),
                                        StrokeThickness = 5
                                    };
    
                                    myMap.Children.Add(routeLine);
    
                                    myMap.SetView(locs, new Thickness(30), 0);
                                }
                                else
                                {
                                    MessageBox.Show("No Results found.");
                                }
                            });
                        });
                    }
                    else
                    {
                        MessageBox.Show("Invalid End location.");
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Start location.");
                }
    }

    >>如何设置 bing 地图里面显示中文

    WPF Bing Maps 控件不支持中文,可以参见下面的帖子:

    #How to change map language?
    http://social.msdn.microsoft.com/Forums/en-US/7675fd8b-e18b-4201-b767-bde5bb70d9bf

    在以下链接中整合了很多有关地图的资源,你可以根据需要选择:

    #Bing Maps Resources
    http://social.msdn.microsoft.com/Forums/onedrive/en-US/001db5dc-6fd3-4723-8654-971865ea281e/bing-maps-resources?forum=vemapcontroldev


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年6月9日 5:41
    版主