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 –