0
我正在玩CLLocationCoordinate2D數組中的多邊形。 這是代碼:錯誤的座標順序的多邊形
int coordsLen = [self.coordinatesArray count];
CLLocationCoordinate2D *coords = malloc(sizeof(CLLocationCoordinate2D) * coordsLen);
NSLog(@"count: %d", coordsLen);
for (int i=0; i < coordsLen; i++)
{
coordinates *coordObj = (coordinates *)[self.coordinatesArray objectAtIndex:i];
coords[i] = CLLocationCoordinate2DMake(coordObj.latitude, coordObj.longitude);
}
self.polygon = [MKPolygon polygonWithCoordinates:coords count:coordsLen];
free(coords);
其結果是,代替顯示我的矩形(如座標的順序進self.coordatesArray是)它表明我一個沙漏。
即使我使用fromPoint構造函數,我得到了相同的結果:
int coordsLen = [self.coordinatesArray count];
MKMapPoint points[coordsLen];
for (int i=0; i < coordsLen; i++)
{
coordinates *coordObj = (coordinates *)[self.coordinatesArray objectAtIndex:i];
CLLocationCoordinate2D c = {coordObj.latitude,coordObj.longitude};
points[i] = MKMapPointForCoordinate(c);
}
self.polygon = [MKPolygon polygonWithPoints:points count:coordsLen];
這是我的多邊形添加爲疊加到地圖:
self.polygonView = nil;
[self.mapView addOverlay:self.polygon];
[self.mapView setVisibleMapRect:[self.polygon boundingMapRect] animated:TRUE];
這些座標:
coord1 = {
latitude = "45.546112";
longitude = "9.11805";
};
coord2 = {
latitude = "45.545773";
longitude = "9.120568";
};
coord3 = {
latitude = "45.544468";
longitude = "9.120629";
};
coord4 = {
latitude = "45.544544";
longitude = "9.118";
};
有什麼建議?
由於提前, 塞繆爾