0

在我的应用程序中,我使用了带有 mapview 的核心位置和 Mapkit 框架。当 wwe 安装应用程序时,它会默认显示类似“想使用当前位置”的警报,而无需编码一次。如果我选择“不允许”,地图视图只会显示蓝色背景?如果我选择“确定”,那么它工作正常。

帮我!

我的代码如下:

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

}
4

2 回答 2

0

如果您选择“不允许”,请致电该代表。

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
     //Do something
}
于 2012-09-26T05:59:50.553 回答
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
    }
}
于 2012-09-26T07:30:43.183 回答