我的应用程序获取以下覆盖区域中的数据。我想用这些边界值在地图上绘制矩形。你有什么主意吗?在此先感谢在地图上绘制矩形
左上边界:30.439217,-95.899668;
右上边界:30.443953,-94.685679;
Left Buttom边界:28.930662,-95.908595;
Right Buttom边界:28.930061,-94.690486;
我的应用程序获取以下覆盖区域中的数据。我想用这些边界值在地图上绘制矩形。你有什么主意吗?在此先感谢在地图上绘制矩形
左上边界:30.439217,-95.899668;
右上边界:30.443953,-94.685679;
Left Buttom边界:28.930662,-95.908595;
Right Buttom边界:28.930061,-94.690486;
,如果你想画的东西基本与线u可以使用这个MKPolyline
尝试下面的代码,请确保您的代理与您的MapView对象
连接- (void) drawRect
{
CLLocation *coordinates1 = [[CLLocation alloc] initWithLatitude:30.439217 longitude:-95.899668];
CLLocation *coordinates2 = [[CLLocation alloc] initWithLatitude:30.443953 longitude:-94.685679];
CLLocation *coordinates3 = [[CLLocation alloc] initWithLatitude:28.930061 longitude:-94.690486];
CLLocation *coordinates4 = [[CLLocation alloc] initWithLatitude:28.930662 longitude:-95.908595];
NSMutableArray *locationCoordinates = [[NSMutableArray alloc] initWithObjects:coordinates1,coordinates2,coordinates3,coordinates4,coordinates1, nil];
int numberOfCoordinates = [locationCoordinates count];
CLLocationCoordinate2D coordinates[numberOfCoordinates];
for (NSInteger i = 0; i < [locationCoordinates count]; i++) {
CLLocation *location = [locationCoordinates objectAtIndex:i];
CLLocationCoordinate2D coordinate = location.coordinate;
coordinates[i] = coordinate;
}
MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:coordinates count:numberOfCoordinates];
[self.myMapView addOverlay:polyLine];
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
polylineView.strokeColor = [UIColor redColor];
polylineView.lineWidth = 1.0;
return polylineView;
}
既然您已经提出了一般性问题,我只能给您一个关于答案的一般提示。
MKMapView有一个方法convertCoordinate:toPointToView:
它将坐标转换到视图中的一个点。您可以使用它来绘制叠加层。
首先:您想要
#import <QuartzCore/QuartzCore.h>
那么做到这一点:
CLLocationCoordinate2D koor = CLLocationCoordinate2DMake(30.439217,-95.899668);
CLLocationCoordinate2D koor2 = CLLocationCoordinate2DMake(30.443953,-94.685679);
CLLocationCoordinate2D koor3 = CLLocationCoordinate2DMake(28.930662,-95.908595);
CGPoint point1 = [mapView convertCoordinate:koor toPointToView:mapView];
CGPoint point2 = [mapView convertCoordinate:koor2 toPointToView:mapView];
CGPoint point3 = [mapView convertCoordinate:koor3 toPointToView:mapView];
UIView *someView = [[UIView alloc]initWithFrame:CGRectMake(point1.x, point1.y, point2.x-point1.x, point3.y-point1.y)];
[self viewBicimle:someView];
[someView setBackgroundColor:[UIColor clearColor]];
[someView.layer setBorderColor:[[[UIColor blackColor] colorWithAlphaComponent:1.0] CGColor]];
[someView.layer setBorderWidth:1.0];
[mapView addSubview:someView];
[someView release];
但这只会对一个固定的一些MapView的工作。当您移动地图将幻灯片...
添加的子视图不会随地图平铺 – adauguet