zoukankan      html  css  js  c++  java
  • 获取当前位置信息-ios

    locationManager= [[CLLocationManager alloc] init];//位置管理器
            locationManager.desiredAccuracy = kCLLocationAccuracyBest;//精度,设可而止
            locationManager.delegate = self;//设置委托
            locationManager.distanceFilter = 100.0f;//距离删选器
            [locationManager startUpdatingLocation]; //启动位置管理器
    
    #pragma mark -
    #pragma mark locationManager
    -  (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        //获取所在地城市名
        CLGeocoder *geocoder=[[CLGeocoder alloc]init];
        [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks,NSError *error)
         {
             for(CLPlacemark *placemark in placemarks)
             {
                 
                NSString *str1=[[placemark.addressDictionary objectForKey:@"Name"] substringFromIndex:0];
                NSLog(@"%@", [NSString stringWithFormat:@"我的位置:%@",str1]);
                 UITextView *locText = (UITextView*)[self.view viewWithTag:];
             }
         }];
        //map region
        [geocoder release];
    }
    - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
    {
        
        if (error.code == kCLErrorDenied) {
            [[[[UIAlertView alloc] initWithTitle:@"错误信息"
                                         message:@"无法获取您的定位信息"
                                        delegate:nil
                               cancelButtonTitle:@"OK"
                               otherButtonTitles:nil] autorelease] show];
            [locationManager stopUpdatingLocation];
        }
    }
  • 相关阅读:
    vue2.0 练习项目-外卖APP(2)
    vue2.0 练习项目-外卖APP(1)
    迈向全栈开发学习(3)
    迈向全栈开发学习(2)
    迈向全栈开发学习(1)
    前端到后台ThinkPHP开发整站(完)
    前端到后台ThinkPHP开发整站(7)
    前端到后台ThinkPHP开发整站(6)
    前端到后台ThinkPHP开发整站(5)
    uniapp 设置全局scss生效
  • 原文地址:https://www.cnblogs.com/jiackyan/p/3259544.html
Copyright © 2011-2022 走看看