2012-09-26 35 views
0

在我的應用程序中,我使用mapview的核心位置& Mapkit框架。當我們安裝應用程序時,默認情況下默認顯示爲「想要使用當前位置」的提醒,而無需一次性編碼。如果我選擇「不允許」,地圖視圖只顯示藍色背景?如果我選擇「確定」,那麼它工作正常。使用mapview提醒選擇

幫幫我!

我的代碼如下:

Appdelegate.m

CLLocationManager *locationManager; 

    CLLocation *userLocation; 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 

    [self createEditableCopyOfDatabaseIfNeeded]; 

    //=========================================Location Manager 

    if(locationManager == nil) 

     locationManager =[[CLLocationManager alloc] init]; 

    self.locationManager.delegate = self; 

    self.locationManager.desiredAccuracy= kCLLocationAccuracyBest; 

    self.locationManager.distanceFilter= 5; 

    [locationManager startUpdatingLocation]; 
    [locationManager startUpdatingHeading]; 
    //========================================== 
} 

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ 
    NSLog(@"new location"); 

    self.userLocation=newLocation; 

    NSLog(@"user llocation %f , %f",userLocation.coordinate.latitude,userLocation.coordinate.longitude); 

    [self.locationManager startMonitoringSignificantLocationChanges]; 
} 


Mapview.h 
{ 
IBOutlet MKMapView *map; 

     CLLocation   *currentLocation; 
     NSString   *specificLatitude; 
     NSString   *specificLongitude; 

    MKCoordinateRegion region; 
} 

Mapview.m 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    [APPDELEGATE.locationManager startUpdatingLocation]; 


} 
- (void)viewWillAppear:(BOOL)animated 
{ 
self.map.delegate = self; 

    // Ensure that you can view your own location in the map view. 
    [self.map setShowsUserLocation:YES]; 
} 

-(void)viewDidAppear:(BOOL)animated{ 


    currentLocation =APPDELEGATE.userLocation; 

    region.center = self.currentLocation.coordinate; 
    MKCoordinateSpan span; 
    span.latitudeDelta = 0.05; 
    span.longitudeDelta = 0.03; 
    region.span = span; 
    [map setRegion:region animated:TRUE]; 
    [self searchPressed]; 

    NSLog(@"Mapview %f %f",currentLocation.coordinate.latitude,currentLocation.coordinate.longitude 
     ); 

} 

回答

0

如果選擇 「不允許」,則調用該委託。

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
    //Do something 
} 
+0

沒有它不工作 – user1673099

+0

你應該改變縮放級別則顯示整個地圖視圖。該提醒是蘋果的默認,所以我們不能做任何事情。 – Mani

0

我還沒試過這個,但也許你可以測試看看它是否工作。

對於顯示地圖視圖的視圖控制器,請嘗試符合UIAlertViewDelegate。

然後在警報視圖委託回調方法,你可以做任何你想要的,如果它的工作原理:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    // you need to type the exact title of the alert popup 
    // button index starts from 0 (left most button), so if the are 2 buttons 
    // and "Don't allow" button is on the right, the button == 1 is that button 
    // the user tapped on 

    if([alertView.title isEqualToString:@"Type Exact Alert Title Here"] && buttonIndex == 1) 
    { 
     // do something 
    } 
}