让百度地图只再应用程序启动时,仅取一次用户坐标信息

方法: 再百度地图的委托方法   - (void)mapView:(BMKMapView *)mapView didUpdateUserLocation:(BMKUserLocation *)userLocation   中设置:

[mapView setShowsUserLocation:NO];

例子代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    configData = [NSUserDefaults standardUserDefaults];     //初始化对象

    //启动BMKMapManager  (加载百度地图前,必须先启动BMKMapManager)
    _mapManager = [[BMKMapManager alloc]init];
    BOOL ret = [_mapManager start:@"2772BD5CAFF652491F65707D6D5E9ABEBF3639CC"generalDelegate:self];
    if (!ret) {
        NSLog(@"manager start failed!");
    }
    //创建一张百度地图
    _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0,600, 5,5)];
    [_mapView setShowsUserLocation:YES];      //此处设置为YES
    _mapView.delegate = self;
    [self.view addSubview:_mapView];
    
}
- (void)mapView:(BMKMapView *)mapView didUpdateUserLocation:(BMKUserLocation *)userLocation
{
    if (userLocation != nil) {
        [configData setObject:[NSString stringWithFormat:@"%f",userLocation.location.coordinate.latitude] forKey:@"lat"];
        [configData setObject:[NSString stringWithFormat:@"%f",userLocation.location.coordinate.longitude] forKey:@"lng"];
        NSLog(@"程序初始化获取的经纬度=%@,%@",[configData objectForKey:@"lng"],[configData objectForKey:@"lat"]);
    }
    //可以保证用户的坐标只取一次
    [mapView setShowsUserLocation:NO];   //此处设置为NO
}

 

此方法可以在一定程度上提高应用程序的运行速度并且减少用户的耗电量。

 

posted @ 2013-05-26 02:26  ygm900  阅读(515)  评论(0编辑  收藏  举报