Windows phone 8 如何在windows phone 8地图控件中的两个特定位置之间绘制路线?
我看到了这段代码,但它只在通过搜索指定目的地时起作用! 我需要使用纬度和经度导航到特定位置Windows phone 8 如何在windows phone 8地图控件中的两个特定位置之间绘制路线?,windows-phone-8,Windows Phone 8,我看到了这段代码,但它只在通过搜索指定目的地时起作用! 我需要使用纬度和经度导航到特定位置 GeocodeQuery Mygeocodequery = null; Mygeocodequery = new GeocodeQuery(); Mygeocodequery.SearchTerm = "Seattle, WA"; Mygeocodequery.GeoCoordinate = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude,MyGeo
GeocodeQuery Mygeocodequery = null;
Mygeocodequery = new GeocodeQuery();
Mygeocodequery.SearchTerm = "Seattle, WA";
Mygeocodequery.GeoCoordinate = new GeoCoordinate(MyGeoPosition.Coordinate.Latitude,MyGeoPosition.Coordinate.Longitude);
Mygeocodequery.QueryCompleted += Mygeocodequery_QueryCompleted;
Mygeocodequery.QueryAsync();
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();
}
}
GeocodeQuery Mygeocodequery=null;
Mygeocodequery=新的GeocodeQuery();
Mygeocodequery.SearchTerm=“华盛顿州西雅图”;
Mygeocodequery.GeoCoordinate=新的地理坐标(MyGeoPosition.Coordinate.Latitude,MyGeoPosition.Coordinate.Longitude);
Mygeocodequery.QueryCompleted+=Mygeocodequery\u QueryCompleted;
Mygeocodequery.QueryAsync();
void Mygeocodequery\u QueryCompleted(对象发送方,QueryCompletedEventArgs e)
{
如果(e.Error==null)
{
MyQuery=newRouteQuery();
MyCoordinates.Add(e.Result[0].地理坐标);
MyQuery.Waypoints=支点;
MyQuery.QueryCompleted+=MyQuery\u QueryCompleted;
MyQuery.QueryAsync();
Mygeocodequery.Dispose();
}
}
void MyQuery\u QueryCompleted(对象发送方,QueryCompletedEventArgs e)
{
如果(e.Error==null)
{
路径MyRoute=e.结果;
MapRoute MyMapRoute=新的MapRoute(MyRoute);
MyMap.AddRoute(MyMapRoute);
Dispose();
}
}
这里是一个示例代码(假设您已经有了源坐标和目标坐标)
public部分类Foo:PhoneApplicationPage
{
列表坐标=新列表();
公共食物(
{
初始化组件();
}
私有void SetMapCoordinates()
{
MyCoordinates.Add(新地理坐标(Target.Latitude,Target.Longitude));
MyCoordinates.Add(新地理坐标(源纬度、源经度));
DrawMyRoute();
}
void MyRoute()
{
MyQuery=newRouteQuery();
MyQuery.TravelMode=TravelMode.Walking;
MyQuery.Waypoints=支点;
MyQuery.QueryCompleted+=MyQuery\u QueryCompleted;
MyQuery.QueryAsync();
}
void MyQuery\u QueryCompleted(对象发送方,QueryCompletedEventArgs e)
{
如果(e.Error==null)
{
路径MyRoute=e.结果;
MapRoute MyMapRoute=新的MapRoute(MyRoute);
MyMapRoute.Color=(Colors.Blue);
添加路径(MyMapRoute);
#区域绘制源位置椭圆
椭圆myCircle=新椭圆();
myCircle.Fill=新的SolidColorBrush(Colors.Blue);
myCircle.高度=20;
myCircle.宽度=20;
不透明度=50;
MapOverlay myLocationOverlay=新建MapOverlay();
myLocationOverlay.Content=myCircle;
myLocationOverlay.PositionOrigin=新点(0.5,0.5);
myLocationOverlay.GeoCoordinate=坐标转换器.ConvertGeocoordinate(源位置);
MylocationLayer=新映射层();
添加(myLocationOverlay);
MyLocMap.Layers.Add(MylocationLayer);
#端区
#区域绘制目标位置椭圆
椭圆CarCircle=新椭圆();
CarCircle.Fill=新的SolidColorBrush(Colors.Red);
高度=20;
CarCircle.宽度=20;
不透明度=50;
MapOverlay CarLocationOverlay=新建MapOverlay();
CarLocationOverlay.Content=CarCircle;
CarLocationOverlay.PositionOrigin=新点(0.5,0.5);
CarLocationOverlay.GeoCoordinate=坐标变换器.ConvertGeocoordinate(TargetLocation);
CarlocationLayer=新映射层();
CarlocationLayer.Add(CarLocationOverlay);
MyLocMap.Layers.Add(CarlocationLayer);
#端区
Dispose();
}
}
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
SetMapCoordinates();
}
}
这里是一个示例代码(假设您已经有了源坐标和目标坐标)
public部分类Foo:PhoneApplicationPage
{
列表坐标=新列表();
公共食物(
{
初始化组件();
}
私有void SetMapCoordinates()
{
MyCoordinates.Add(新地理坐标(Target.Latitude,Target.Longitude));
MyCoordinates.Add(新地理坐标(源纬度、源经度));
DrawMyRoute();
}
void MyRoute()
{
MyQuery=newRouteQuery();
MyQuery.TravelMode=TravelMode.Walking;
MyQuery.Waypoints=支点;
MyQuery.QueryCompleted+=MyQuery\u QueryCompleted;
MyQuery.QueryAsync();
}
void MyQuery\u QueryCompleted(对象发送方,QueryCompletedEventArgs e)
{
如果(e.Error==null)
{
路径MyRoute=e.结果;
MapRoute MyMapRoute=新的MapRoute(MyRoute);
MyMapRoute.Color=(Colors.Blue);
添加路径(MyMapRoute);
#区域绘制源位置椭圆
椭圆myCircle=新椭圆();
myCircle.Fill=新的SolidColorBrush(Colors.Blue);
myCircle.高度=20;
myCircle.宽度=20;
不透明度=50;
MapOverlay myLocationOverlay=新建MapOverlay();
myLocationOverlay.Content=myCircle;
myLocationOverlay.PositionOrigin=新点(0.5,0.5);
myLocationOverlay.GeoCoordinate=坐标转换器.ConvertGeocoordinate(源位置);
MylocationLayer=新映射层();
添加(myLocationOverlay);
public partial class Foo : PhoneApplicationPage
{
List<GeoCoordinate> MyCoordinates = new List<GeoCoordinate>();
public Foo()
{
InitializeComponent();
}
private void SetMapCoordinates()
{
MyCoordinates.Add(new GeoCoordinate(Target.Latitude, Target.Longitude));
MyCoordinates.Add(new GeoCoordinate(Source.Latitude, Source.Longitude));
DrawMyRoute();
}
void MyRoute()
{
MyQuery = new RouteQuery();
MyQuery.TravelMode = TravelMode.Walking;
MyQuery.Waypoints = MyCoordinates;
MyQuery.QueryCompleted += MyQuery_QueryCompleted;
MyQuery.QueryAsync();
}
void MyQuery_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
if (e.Error == null)
{
Route MyRoute = e.Result;
MapRoute MyMapRoute = new MapRoute(MyRoute);
MyMapRoute.Color = (Colors.Blue);
MyLocMap.AddRoute(MyMapRoute);
#region Draw source location ellipse
Ellipse myCircle = new Ellipse();
myCircle.Fill = new SolidColorBrush(Colors.Blue);
myCircle.Height = 20;
myCircle.Width = 20;
myCircle.Opacity = 50;
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = myCircle;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = CoordinateConverter.ConvertGeocoordinate(SourceLocation);
MylocationLayer = new MapLayer();
MylocationLayer.Add(myLocationOverlay);
MyLocMap.Layers.Add(MylocationLayer);
#endregion
#region Draw target location ellipse
Ellipse CarCircle = new Ellipse();
CarCircle.Fill = new SolidColorBrush(Colors.Red);
CarCircle.Height = 20;
CarCircle.Width = 20;
CarCircle.Opacity = 50;
MapOverlay CarLocationOverlay = new MapOverlay();
CarLocationOverlay.Content = CarCircle;
CarLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
CarLocationOverlay.GeoCoordinate = CoordinateConverter.ConvertGeocoordinate(TargetLocation);
CarlocationLayer = new MapLayer();
CarlocationLayer.Add(CarLocationOverlay);
MyLocMap.Layers.Add(CarlocationLayer);
#endregion
MyQuery.Dispose();
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SetMapCoordinates();
}
}