我有一个应用程序与Bing地图,我需要绘制用户的路线dinamically。 现在我只能用图钉追踪用户的位置。有没有一种方法来绘制路线?在运行时绘制路线
更新1: 我使用这个处理程序分配给geolocator.positionChanged:
private void geolocator_DrawRoute(Geolocator sender, PositionChangedEventArgs args)
{
// Need to get back onto UI thread before updating location information
this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(
() =>
{
//Get the current location
Location location = new Location(args.Position.Coordinate.Point.Position.Latitude,
args.Position.Coordinate.Point.Position.Longitude);
_rotta.Add(location);
if (_rotta.Count > 1)
{
var polyline = new MapPolyline { Locations = _rotta, Color = Colors.Blue, Width = 3 };
_shapeLayer.Shapes.Add(polyline);
}
//Update the position of the GPS pushpin
MapLayer.SetPosition(GpsPushpin, location);
//Update the map view to the current GPS location
MyMap.SetView(location, 18);
}));
}
更新2:
private void geolocator_DrawRoute(Geolocator sender, PositionChangedEventArgs args)
{
// Need to get back onto UI thread before updating location information
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(
() =>
{
//Get the current location
var location = new Location(args.Position.Coordinate.Point.Position.Latitude, args.Position.Coordinate.Point.Position.Longitude);
_rottaLoc.Add(location);
if (_rotta == null)
{
_rotta = new MapPolyline { Locations = _rottaLoc, Color = Colors.Blue, Width = 4 };
}
else
{
_rotta.Locations = _rottaLoc;
}
_shapeLayer.Shapes.Add(_rotta);
//Update the position of the GPS pushpin
MapLayer.SetPosition(GpsPushpin, location);
//Update the map view to the current GPS location
MyMap.SetView(location, 18);
}));
}
您想在用户在地图上移动时绘制线条,即追踪他们的路线吗?或者你想绘制一条行车路线并显示沿着该路线的用户位置? – rbrundritt 2015-02-06 17:38:03
@rbrunditt我想画一条随着用户移动的折线!我可以使用geolocator的PositionChanged事件吗? – 2015-02-06 17:39:26
是的,你可以使用PositionChanged事件 – rbrundritt 2015-02-10 20:35:14