IOS培训

亿元级外企ios培训企业

  • 全国服务监督电话4001118989
  • IOS8获取地理位置信息

    发布:iOS培训  来源:IOS开发教程  时间: 2015年06月07日

  • IOS8获取地理位置信息...

  • Info.plist设置

    在plist里增加两个字段

    NSLocationAlwaysUsageDescription

     

    NSLocationWhenInUseUsageDescription

    值都设置为NSString类型的YES

    //设置

    - (void)_startGPS

    {

      [LocalInfosharedInstance].locationManager= [[CLLocationManageralloc]init];

      [LocalInfosharedInstance].locationManager.delegate=self;

      [LocalInfosharedInstance].locationManager.desiredAccuracy=kCLLocationAccuracyBest;

      if([[LocalInfosharedInstance].locationManagerrespondsToSelector:@selector(requestAlwaysAuthorization)])

      {

        [[LocalInfosharedInstance].locationManagerrequestWhenInUseAuthorization];

        [[LocalInfosharedInstance].locationManagerrequestAlwaysAuthorization];//永久授权

      }

      [[LocalInfosharedInstance].locationManagerstartUpdatingLocation];

      [[LocalInfosharedInstance].locationManagerperformSelector:@selector(stopUpdatingLocation)withObject:nilafterDelay:45];

     

    }

    //回调

    #pragma mark - CLLocationManagerDelegate

    - (void)locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation

    {

      NSTimeIntervallocationAge = -[newLocation.timestamptimeIntervalSinceNow];

      if(locationAge >5.0)return;

       

      if(newLocation.horizontalAccuracy<0)return;

       

      if([LocalInfosharedInstance].currentLocation==nil|| [LocalInfosharedInstance].currentLocation.horizontalAccuracy> newLocation.horizontalAccuracy)

      {

        [LocalInfosharedInstance].currentLocation= newLocation;

        [ConfigDataSourcegetCityInfoWith:[LocalInfosharedInstance].currentLocation];

         

        //本地更新

        [USER_DEFAULTsetObject:[NSStringstringWithFormat:@"%f",[LocalInfosharedInstance].currentLocation.coordinate.latitude]forKey:USER_LOGIN_LATITUDE];

        [USER_DEFAULTsetObject:[NSStringstringWithFormat:@"%f",[LocalInfosharedInstance].currentLocation.coordinate.longitude]forKey:USER_LOGIN_LONGITUDE];

        [USER_DEFAULTsynchronize];

         

        if(newLocation.horizontalAccuracy<= [LocalInfosharedInstance].locationManager.desiredAccuracy)

        {

          [[LocalInfosharedInstance].locationManagerstopUpdatingLocation];

        }

      }

     

    }

  • 上一篇:Objective-C内存管理教程

    下一篇:IOS开发相关设置积累

网站导航
2001-2016 达内时代科技集团有限公司 版权所有 京ICP证8000853号-56