【问题标题】:How can i integrate Radar Overlay on MapView?如何在 MapView 上集成雷达叠加?
【发布时间】:2023-03-28 05:45:01
【问题描述】:

我想在我的 MapView 上集成天气雷达。请任何人帮忙完成这项任务。我已经做了很多谷歌搜索但没有成功。请检查我想要这样做的这张图片。

【问题讨论】:

    标签: ios ipad mkmapview weather-api radar-chart


    【解决方案1】:

    您需要调查 MapKit 叠加层 (MKOverlay)。在您的情况下,您将创建一个MKPolygon

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

    有一个名为 HazardMap 的 Apple 项目示例,它的作用与您尝试做的非常相似,只是在这种情况下它使用的是地震数据。

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

    希望这会有所帮助。

    【讨论】:

    • 是的,我已经检查了 HazardMap,但它没有提供天气信息,并且它正在获取一些与 MyRequirement 不同的文件。感谢您的回复,但确实有任何 api。再次感谢。跨度>
    • 我假设您可以访问源天气数据。您可以尝试programmableweb.com 查找所需数据的来源。
    【解决方案2】:

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

    在头文件(.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.
        // e.g. 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;
    
    }
    

    【讨论】:

    • 你从哪里得到这个方法,我在文档中看不到 ---> MapOverlay * mapOverlay = [[MapOverlay alloc] initWithImageData:[NSData dataWithContentsOfURL:url] withLowerLeftCoordinate:CLLocationCoordinate2DMake(21.652538062803 , -127.620375523875420) 与UpperRightCoordinate:CLLocationCoordinate2DMake(50.406626367301044, -66.517937876818)];
    • 您必须创建包含这些方法的自定义类请检查该类的这些图像。
    • @iosRider 你能看看我关于 mkoverlays 中的动画 gif 的问题吗stackoverflow.com/questions/20558591/…
    猜你喜欢
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多