STANLEY
STANLEY

Reputation: 181

place pin on mapview by coordinates sent from appdelegate

This takes me days..I could not make it work. I write a method that places a pin on map as below:

- (void) SetMaps:(NSString *)Lats :(NSString *)lons;
{
    if([upLo isEqualToString:@"Y"])
    {
        NSLog(@"setting maps:%@,%@",Lats,lons);
        [mapView setMapType:MKMapTypeStandard];
        [mapView setZoomEnabled:YES];
        [mapView setScrollEnabled:YES];
        [mapView setMapType:MKMapTypeStandard];
        [mapView setZoomEnabled:YES];
        [mapView setScrollEnabled:YES];
        MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
        region.center.latitude = [Lats doubleValue] ;
        region.center.longitude = [lons doubleValue];
        region.span.longitudeDelta = 0.01f;
        region.span.latitudeDelta = 0.01f;
        [mapView setRegion:region animated:YES];
       [mapView setDelegate:self];
        MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
        point.coordinate = region.center;
       [self.mapView addAnnotation:point];

    }
}

This method runs well if I call it in secondViewController.m in a tab bar controll application.

But, I want to call it from appdelegate.m. So in appdelegate.m, I put

secondViewController *Gper=[[secondViewController alloc]init];
[Gper SetMaps:LAT:LON];
[Gper release];

from this NSLog(@"setting maps:%@,%@",Lats,lons); I can see the lat and lons values are correct into this method. However, the map doesnt change to this location.

Whatelse should I do to make it showing new location?

Thanks for any help.

Upvotes: 0

Views: 140

Answers (1)

user529758
user529758

Reputation:

I feel you should learn (Objective-)C memory management and Cocoa conventions better before doing anything further. + alloc returns a new instance of your view controller class, and not the one that is currently displayed.

And begin your class names with a capital letter. And your method names with a lowercase one.

Upvotes: 1

Related Questions