UWP C#:将MapPolygon添加到MapControl
我正在尝试使用以下代码示例(从中检索)将多边形添加到地图中:UWP C#:将MapPolygon添加到MapControl,c#,google-maps,uwp,C#,Google Maps,Uwp,我正在尝试使用以下代码示例(从中检索)将多边形添加到地图中: public void HighlightArea(){ 双中心纬度=myMap.Center.Position.Latitude; 双中心经度=myMap.Center.Position.Longitude; var mapPolygon=新的mapPolygon { 路径=新地理路径(新列表{ 新的基本地理位置(){纬度=中心纬度+0.0005,经度=中心经度-0.001}, 新的基本地理位置(){纬度=中心纬度-0.0005,经
public void HighlightArea(){
双中心纬度=myMap.Center.Position.Latitude;
双中心经度=myMap.Center.Position.Longitude;
var mapPolygon=新的mapPolygon
{
路径=新地理路径(新列表{
新的基本地理位置(){纬度=中心纬度+0.0005,经度=中心经度-0.001},
新的基本地理位置(){纬度=中心纬度-0.0005,经度=中心经度-0.001},
新的基本地理位置(){纬度=中心纬度-0.0005,经度=中心经度+0.001},
新的基本地理位置(){纬度=中心纬度+0.0005,经度=中心经度+0.001},
}),
ZIndex=1,
FillColor=Colors.Red,
StrokeColor=颜色。蓝色,
冲程厚度=3,
strokeshown=false,
};
//将MapPolygon添加到地图控件上的图层。
var MyHighlights=新列表();
添加(mapPolygon);
var HighlightsLayer=新映射元素slayer
{
ZIndex=1,
MapElements=MyHighlights
};
myMap.Layers.Add(HighlightsLayer);
}
多边形最初显示在地图上,但在出现后2秒内消失(逐渐消失)。通过使用从同一链接检索到的示例,我成功地添加了一条粘贴到地图的MapPolyline,这就是为什么我无法理解MapPolygon为什么不会粘贴
什么可能导致多边形褪色?该示例对我很有用。请告诉我您的项目平台版本和操作系统构建版本?我建议您可以先试用官方示例,看看它是否有效。我的目标是Windows 10,版本1803(10.0;Build 17134)@XavierXie msfta您是否尝试运行官方示例,看看它是否对您有效?
public void HighlightArea() {
double centerLatitude = myMap.Center.Position.Latitude;
double centerLongitude = myMap.Center.Position.Longitude;
var mapPolygon = new MapPolygon
{
Path = new Geopath(new List<BasicGeoposition> {
new BasicGeoposition() {Latitude=centerLatitude+0.0005, Longitude=centerLongitude-0.001 },
new BasicGeoposition() {Latitude=centerLatitude-0.0005, Longitude=centerLongitude-0.001 },
new BasicGeoposition() {Latitude=centerLatitude-0.0005, Longitude=centerLongitude+0.001 },
new BasicGeoposition() {Latitude=centerLatitude+0.0005, Longitude=centerLongitude+0.001 },
}),
ZIndex = 1,
FillColor = Colors.Red,
StrokeColor = Colors.Blue,
StrokeThickness = 3,
StrokeDashed = false,
};
// Add MapPolygon to a layer on the map control.
var MyHighlights = new List<MapElement>();
MyHighlights.Add(mapPolygon);
var HighlightsLayer = new MapElementsLayer
{
ZIndex = 1,
MapElements = MyHighlights
};
myMap.Layers.Add(HighlightsLayer);