MapPolyline.Path.Add 不起作用

本文关键字:不起作用 Add Path MapPolyline | 更新日期: 2023-09-27 17:56:08

我在应用程序中使用了以下代码:

var line = new MapPolyline();
line.StrokeColor = Colors.Red;
line.StrokeThickness = 2;
line.Path.Add(new GeoCoordinate(lat,long));   //<== this
line.Path.Add(new GeoCoordinate(lat, long));  //<== and this
MyMap.MapElements.Add(line);

我用的是Windows Phone 8.1在标记的位置收到此错误:

"Windows.Devices.Geolocation.Geopath"不包含"Add"

的定义,并且找不到接受类型为"Windows.Devices.Geolocation.Geopath"的第一个参数的扩展方法"Add"(您是否缺少使用指令或程序集引用?

工作怎么办??

附言我有使用Windows.Devices.Geolocation;

MapPolyline.Path.Add 不起作用

错。您必须单独生成列表并使用构造函数传递它:

List<BasicGeoposition> positions = new List<BasicGeoposition>();
// Now add your positions:
positions.Add(new BasicGeoposition(){ Latitude = lat, Longitude = long});   //<== this
positions.Add(new BasicGeoposition(){ Latitude = lat, Longitude = long));  //<== and this
Geopath path = new Geopath(positions);
var line = new MapPolyline();
// Set your path
line.Path = path;
line.StrokeColor = Colors.Red;
line.StrokeThickness = 2;
MyMap.MapElements.Add(line);

我知道 - 这有点棘手。但我认为目的是一旦在地图上绘制了多边形,就无法操纵路径。