Windows Phone 8.1,使用Map(不是Map Control)

时间:2016-01-19 09:42:15

标签: routes bing-maps

Windows Phone 8.1 ,使用Map(不是Map Control)如何显示两个位置之间的路由?最近几天我正在寻找它,但起始位置是当前位置(我不想要)和最终位置我使用具有SearchTerm属性的GeocodeQuery,而我给了我自己的位置(如孟买)对于Banglore,它必须显示路线以及可用的不同路线(如果可能的话)和SearchTerm一样,只需传递名称即可返回GeoCoordinate。

当前代码:

公共部分类MainPage:PhoneApplicationPage     {         //构造函数         列出MyCoordinates = new List();         RouteQuery MyQuery = null;         GeocodeQuery Mygeocodequery = null;

    public MainPage()
    {
        InitializeComponent();
        this.GetCoordinates();
        Map Mymap = new Map();

        // Sample code to localize the ApplicationBar
        //BuildLocalizedApplicationBar();
    }

    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));
            MyMap.ZoomLevel = 11;
            Mygeocodequery = new GeocodeQuery();


            Mygeocodequery.SearchTerm = "Mumbai";
            Mygeocodequery.GeoCoordinate = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude, MyGeoPosition.Coordinate.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)
        {
            // Something else happened while acquiring the location.
            MessageBox.Show(ex.Message);
        }
    }
    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();
        }
    }

         void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
    {
        if (e.Error == null)
        {
            Route MyRoute = e.Result;
            MapRoute MyMapRoute = new MapRoute(MyRoute);
            MyMap.AddRoute(MyMapRoute);
            MyQuery.Dispose();
        }
    }


    }

在上面的代码中,我希望传递我的起始位置,类似于SearchTerm属性,它将识别纬度和经度。 请帮助, 感谢。

0 个答案:

没有答案