How can i integrate Radar Overlay on MapView?
Asked Answered
S

2

8

I want to Integrate Weather radar on my MapView.Please anyone help on doing this task.I have done so many googling but not get succeed.Please check this image i wanted to do like this. enter image description here

Springtime answered 5/3, 2012 at 15:5 Comment(0)
S
3

I have done something like this for achieving this task:

in header file(.h)

@interface RDViewController : UIViewController{

    UIImage *image ;
}
@property (strong, nonatomic) IBOutlet MKMapView *mapView;

@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;

@property (strong, nonatomic) IBOutlet UIImageView *imageView; 

in .m file

@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;

}

enter image description here enter image description here

Springtime answered 27/3, 2012 at 15:35 Comment(3)
Where did you get this method from I can't see it in the documentation ---> MapOverlay * mapOverlay = [[MapOverlay alloc] initWithImageData:[NSData dataWithContentsOfURL:url] withLowerLeftCoordinate:CLLocationCoordinate2DMake(21.652538062803, -127.620375523875420) withUpperRightCoordinate:CLLocationCoordinate2DMake(50.406626367301044, -66.517937876818)];Rubel
You have to create custom Class which contains these methods Please check these images of that class.Springtime
@iosRider Could you check out my question related to animated gifs in mkoverlays #20559091Accordant
C
3

You need investigate MapKit overlays (MKOverlay). In your case you will be creating a MKPolygon.

You will need to create an array of MKMapPoints from your weather radar data, then create a MKPolygon from these points and add it your map as an overlay.

There is a sample Apple project called HazardMap which does something very similar to what you are trying to do, except in this case it is using earthquake data.

Also check out the WWWDC 2011 presentation "Visualizing Information Geographically with MapKit". Around the 30 minute mark they start talking about Overlays.

Hope this helps.

Cooperative answered 8/3, 2012 at 12:3 Comment(2)
yes I have checked HazardMap but it's not providing weather information and it's taking some files which is some thing different that MyRequirement.Thanks for the response but do have any api for this.Thanks once again.Springtime
I assumed that you had access to the source weather data. You could try programmableweb.com to find a source for the data you require.Cooperative
S
3

I have done something like this for achieving this task:

in header file(.h)

@interface RDViewController : UIViewController{

    UIImage *image ;
}
@property (strong, nonatomic) IBOutlet MKMapView *mapView;

@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;

@property (strong, nonatomic) IBOutlet UIImageView *imageView; 

in .m file

@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;

}

enter image description here enter image description here

Springtime answered 27/3, 2012 at 15:35 Comment(3)
Where did you get this method from I can't see it in the documentation ---> MapOverlay * mapOverlay = [[MapOverlay alloc] initWithImageData:[NSData dataWithContentsOfURL:url] withLowerLeftCoordinate:CLLocationCoordinate2DMake(21.652538062803, -127.620375523875420) withUpperRightCoordinate:CLLocationCoordinate2DMake(50.406626367301044, -66.517937876818)];Rubel
You have to create custom Class which contains these methods Please check these images of that class.Springtime
@iosRider Could you check out my question related to animated gifs in mkoverlays #20559091Accordant

© 2022 - 2024 — McMap. All rights reserved.