我怎样才能整合雷达覆盖在MapView上?

我想在我的MapView上集成天气雷达。请大家帮忙做这个任务。我做了这么多的Googlesearch,但没有成功。请检查这个图像,我想这样做。 在这里输入图像说明

我做了这样的事情来完成这个任务:

在头文件(.h)

@interface RDViewController : UIViewController{ UIImage *image ; } @property (strong, nonatomic) IBOutlet MKMapView *mapView; @property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator; @property (strong, nonatomic) IBOutlet UIImageView *imageView; 

在.m文件中

 @implementation RDViewController @synthesize mapView; @synthesize activityIndicator; @synthesize imageView; - (void)viewDidLoad { NSURL *url = [NSURL URLWithString: @"http://radar.weather.gov/ridge/Conus/RadarImg/latest_radaronly.gif"]; MapOverlay * mapOverlay = [[MapOverlay alloc] initWithImageData:[NSData dataWithContentsOfURL:url] withLowerLeftCoordinate:CLLocationCoordinate2DMake(21.652538062803, -127.620375523875420) withUpperRightCoordinate:CLLocationCoordinate2DMake(50.406626367301044, -66.517937876818)]; //<LatLonBox><north>50.406626367301044</north><south>21.652538062803</south><east>-66.517937876818</east><west>-127.620375523875420</west></LatLonBox> [mapView addOverlay:mapOverlay]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)viewDidUnload { [self setImageView:nil]; [self setMapView:nil]; [self setActivityIndicator:nil]; [super viewDidUnload]; // Release any retained subviews of the main view. // eg self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return YES; } #pragma Mark - MKOverlayDelgateMethods - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay { MapOverlay *mapOverlay = overlay; MapOverlayView *mapOverlayView = [[MapOverlayView alloc] initWithOverlay:mapOverlay]; return mapOverlayView; } 

在这里输入图像说明在这里输入图像说明

您需要调查MapKit覆盖( MKOverlay )。 在你的情况下,你将创build一个MKPolygon

您需要根据您的天气雷达数据创build一个MKMapPoints数组,然后从这些点创build一个MKPolygon,并将其作为覆盖图添加到您的地图中。

有一个叫做HazardMap的苹果项目,它和你正在做的事情非常相似,除了在这种情况下它正在使用地震数据。

还可以查看WWWDC 2011演示文稿“使用MapKit在地理上可视化信息”。 大约30分钟,他们开始谈论覆盖。

希望这可以帮助。

Interesting Posts