0
我想在我的MKMapView
中画一个红色的矩形。我看到地图,但看不到矩形。我的代码:在MKMapView中绘制矩形
public override void ViewDidLoad()
{
base.ViewDidLoad();
var areaMapView = new AreaMapView();
areaMapView.SetTarget(45.5399396, -73.6534612);
areaMapView.AddZone(new List<Geolocation>()
{
new Geolocation() { Latitude = 25.774, Longitude = -80.190},
new Geolocation() { Latitude = 18.466, Longitude = -66.118},
new Geolocation() { Latitude = 32.321, Longitude = -64.757},
new Geolocation() { Latitude = 25.774, Longitude = -80.190},
});
View = areaMapView;
}
public class AreaMapView : MKMapView
{
public AreaMapView() : base(UIScreen.MainScreen.Bounds)
{
this.ShowsUserLocation = true;
this.MapType = MKMapType.Satellite;
}
public void SetTarget(double longitude, double latitude)
{
this.AddAnnotations(new MKPointAnnotation()
{
Title = "Target",
Coordinate = new CLLocationCoordinate2D(longitude, latitude)
});
}
public void AddZone(List<Geolocation> longitudeAndLatitudePoints)
{
var coords = new CLLocationCoordinate2D[longitudeAndLatitudePoints.Count];
for (int i = 0; i < longitudeAndLatitudePoints.Count; i++)
{
double longitude = longitudeAndLatitudePoints[i].Longitude;
double latitude = longitudeAndLatitudePoints[i].Latitude;
coords[i] = new CLLocationCoordinate2D(longitude, latitude);
}
this.AddOverlay(MKPolyline.FromCoordinates(coords));
}
}
我可以在swift中发布解决方案吗? @Darius –
将它发布给任何使用swift的人,它会被他们提升。 – Darius
有一个答案我没有看到,顺便解决你的问题? @Darius –