首页 > 解决方案 > 在 MapControl 上画一个圆圈

问题描述

我知道通过基本数学生成点然后使用这些点创建 MapPolygon 来绘制圆的技术。

还有其他方法吗?

例如,我看到有一个圆圈类:

public sealed class Geocircle : IGeocircle, IGeoshape

但我不知道如何使用它,似乎没有MapLayer它。

标签: c#uwpuwp-xaml

解决方案


Geocircle用于为给定的位置和半径创建地理圆对象。它经常用于制作地图Geofence,但不用于在地图上显示循环。

有很多方法可以在地图上画一个圆圈

通过基础数学生成点

for (var i = 0; i < 360; i++)
{
//draw a cycle
BasicGeoposition point = new BasicGeoposition() 
{ Latitude = centerLatitude + ri * Math.Cos(3.6 * i * 3.14 / 180), Longitude = centerLongitude + ri * Math.Sin(3.6 * i * 3.14 / 180) };
list.Add(point);
}

椭圆添加到地图

private void MyMap_Loaded(object sender, RoutedEventArgs e)
{
    // Specify a known location.
    BasicGeoposition snPosition = new BasicGeoposition { Latitude = 47.620, Longitude = -122.349 };
    Geopoint snPoint = new Geopoint(snPosition);

    // Create a XAML border.
    var ellipse1 = new Ellipse();
    ellipse1.Fill = new SolidColorBrush(Windows.UI.Colors.Coral);
    ellipse1.Width = 200;
    ellipse1.Height = 200;

    // Center the map over the POI.
    MyMap.Center = snPoint;
    MyMap.ZoomLevel = 14;

    // Add XAML to the map.
    MyMap.Children.Add(ellipse1);
    MapControl.SetLocation(ellipse1, snPoint);
    MapControl.SetNormalizedAnchorPoint(ellipse1, new Point(0.5, 0.5));
}

推荐阅读