【问题标题】:Alert selection with mapview使用地图视图进行警报选择
【发布时间】:2012-09-26 05:55:11
【问题描述】:

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

帮帮我!

我的代码如下:

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

}

【问题讨论】:

    标签: iphone ios xcode google-maps core-location


    【解决方案1】:

    如果您选择“不允许”,则调用此委托。

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

    【讨论】:

    • 您应该更改缩放级别,然后显示整个地图视图。该警报是苹果的默认设置,因此我们无能为力。
    【解决方案2】:

    我还没有尝试过,但也许你可以测试一下它是否有效。

    对于显示地图视图的视图控制器,请尝试符合 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
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-03
      • 1970-01-01
      • 2012-08-29
      相关资源
      最近更新 更多